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 App using Tailwind CSS

@demi05

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


I could not figure out a way to handle the logic for days in February. Any advice?

Community feedback

P
Cassidy 160

@CMac450

Posted

I made an array to hold known leap years starting from 1952 up until 2020. If the value of the year input was included in the leapYears array, the month value was 2, and the day value was greater than 29, then the entire date would be flagged as invalid.

If the 'years' value was not included in 'leapYears', the 'month' value was 2, and the 'day' value was greater than 28, then the entire date would be flagged as invalid as well.

const leapYears = [1952, 1956, 1960, 1964, 1968, 1972, 1976, 1980, 1984, 1988, 1992, 1996, 2000, 2004, 2008, 2012, 2016, 2020];

let isDateValid = false;

let day = userInputDay;
let month = userInputMonth;
let year = userInputYear;

if(leapYears.includes(parseInt(year)) && parseInt(month) === 2 && parseInt(day) > 29 {
    isDateValid = false;
} else if(!leapYears.includes(parseInt(year)) && parseInt(month) === 2 && parseInt(day) > 28 {
    isDateValid = false;
}

//"isDateValid = false" = show date error

Let me know if this helped you in any way. Great work with your solution!

Marked as helpful

0

@demi05

Posted

@CMac450 Thank you so much. I didn't really know how to approach it

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