Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Age Calculator

@mypetonthenet

Desktop design screenshot for the Age calculator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Community feedback

Daniel 🛸 44,230

@danielmrz-dev

Posted

Olá @mypetonthenet!

Seu projeto ficou excelente!

Uma sugestão é simplificar a lógica de validação utilizando operadores ternários. Isso pode reduzir a quantidade de código e tornar o mesmo mais conciso. Aqui está um exemplo para a função validateDay():

function validateDay() {
    erroDia.innerHTML = diaNascimento.value.length === 0 ? 'This field is required' : (diaNascimento.value > 31 ? 'Must be a valid day' : '');
    erroDia.style.opacity = diaNascimento.value.length === 0 || diaNascimento.value > 31 ? '1' : '0';
    textDay.style.color = diaNascimento.value.length === 0 || diaNascimento.value > 31 ? '#F25D07' : '#716f6f';
    diaNascimento.style.border = diaNascimento.value.length === 0 || diaNascimento.value > 31 ? '1px solid #F25D07' : '1px solid #dbdbdb';
}

Essa abordagem utiliza operadores ternários para simplificar as condições e as atribuições de valores, resultando em um código mais curto e fácil de entender. Você pode aplicar uma lógica semelhante para as outras funções de validação.

Espero que ajude!

Marked as helpful

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord