Responsive Age calculator app

Solution retrospective
I need help implementing logic to handle invalid dates entered by the user, such as 31/04/1991 (since April has only 30 days).
Please log in to post a comment
Log in with GitHubCommunity feedback
- P@johnnygerard
Sorry, I thought you were asking for how to compute the age.
For the date validation, I used this function:
const isNonexistent = (date: Date, year: number, month: number, day: number): boolean => { return date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day; }
Here is a better function:
/** * Validates if the given year, month, and day form a valid date. * * @param {number} year - The year to validate. * @param {number} month - The month to validate (1-12). * @param {number} day - The day to validate. * @returns {boolean} True if the date is valid, otherwise false. */ const isValidDate = (year: number, month: number, day: number): boolean => { const date = new Date(year, month - 1, day); return ( date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day ); };
Marked as helpful - P@johnnygerard
Hello Yacine,
I already wrote a detailed explanation for this challenge.
Hopefully, that helps you.
Good day.
Marked as helpful
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