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...using CSS Grid & Flexbox

@NxumaloDev

Desktop design screenshot for the Age calculator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


Any criticism are welcome (especially for JavaScript) I think i did not account for the months that have 30 or 28 days and the leap year please help for what i missed thank you !

Community feedback

P
Anastasia 110

@Anarenaa

Posted

Hello👋

I had the same problem with determining the last day of the month. You need to add one function:

//my version of variables
let month = parseInt(document.getElementById('month').value);
let year = parseInt(document.getElementById('year').value);

function getDateInMonth(y, m) {
     return new Date(y, m, 0).getDate()  //when you set the day argument to 0, it calculates the last day of the previous month
}

Then inserting a function into calculations:

if (currentDate >= dobDate){
    dAge = currentDate - dobDate
  }
  else {
    mAge--
    dAge =  getDateInMonth(year, month) + currentDate - dobDate
  }

I can give advice about the error class. You can style it with CSS instead of JS. Only in JS, you will need to add this class to the elements (or better, the container) at the time of the error, if everything is correct, remove it.

By the way, instead of <h2>, use <label> for labels above the fields

СSS

.error label {
  ...
}
.error input {
  ...
}
.error p {
  ...
}

I hope to help😊

Marked as helpful

1

@NxumaloDev

Posted

@Anarenaa Thank you so much. Apologies for responding so late didn't realise i never thanked you.

1

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