Design comparison
SolutionDesign
Community feedback
- @rohanvronPosted 6 months ago
Hey Benji,
Your age calculator looks great!
I noticed a small thing with the date accuracy for months other than the current one. The calculation might be off slightly in those cases.
It seems the code needs an adjustment in how it validates birth dates with different months. Here's an idea:
- Use a Date object to create a representation of the entered date (including year and month). Then, use getDate() to retrieve the correct number of days for that specific month and year (including leap year handling).
This approach ensures accurate validation regardless of the month entered. I've included a code snippet to illustrate this solution:
const inputDate = new Date(year, month - 1, day); if ( inputDate.getDate() !== parseInt(day) || inputDate.getMonth() + 1 !== parseInt(month) || inputDate.getFullYear() !== parseInt(year) ) { return false; } return true; };
Just a heads up about the date validation! Overall, your age calculator is a solid foundation. Keep up the good work! 🚀
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin 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