Age calculator app challenge 🔥

Solution retrospective
Hi everyone👋, Finally completed the Age Calculator App challenge
I thought this will be a pretty easy challenge but it took me a while to figure out the solution, I have only tested the system manually so the chances for typos are more, if you find something do let me know.
I know this is not an optimal solution and there are always room for improvements if you have any suggestions please free to comment below. Open to any feedbacks.
This is the basic logic behind calculating the age and I found out this the easiest and most optimal way.
Happy coding! 😃
const date = new Date(0);
const currentDay = date.getUTCDate();
const currentMonth = date.getUTCMonth();
const currentYear = date.getUTCFullYear();
const birthDate = new Date(`${userYear}-${userMonth}-${userDay}`);
const diff = new Date(Date.now() - birthDate.getTime());
resultingYear = Math.abs(diff.getUTCFullYear() - currentYear);
resultingMonth = Math.abs(diff.getUTCMonth() - currentMonth);
resultingDay = Math.abs(diff.getUTCDate() - currentDay);
Please log in to post a comment
Log in with GitHubCommunity feedback
No feedback yet. Be the first to give feedback on Jose Jimmy's solution.
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