Design comparison
Solution retrospective
The JS I used to calculate the age is mostly accurate, though in some cases it's off by 1 day (e.g. 21-04-1992). I'd be curious if anyone could spot the bug that causes this and tell me how to fix it.
Community feedback
- @elyyysePosted over 1 year ago
Hey - this challenge really took me to task, it was fun to read-thru your completely different approach. I might have spotted the issue that's throwing your result off by a day.
In this
checkIfLeapYear();
function, it looks like you're checking if next year (2024) is a leap year, rather than the year after the inputted birthdate. And since next year happens to be a leap year, you might be subtracting an extra day when this function runs.if (checkIfLeapYear(d2Year + 1) && sDays + eDays >= 366) { remDays = sDays + eDays - 366; d2Year++; } else if (!checkIfLeapYear(d2Year + 1) && sDays + eDays >= 365) { remDays = sDays + eDays - 365; d2Year++; } else { remDays = sDays + eDays; }
Hope this helps! - E
Marked as helpful1@RichusDPosted about 1 year ago@elyyyse Great spot! It seems to be accurate and explains why it was working fine for some years and not others.
0
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