Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 2 years ago

Age calculator app challenge 🔥

Jose Jimmy•290
@jose-jimmy
A solution to the Age calculator app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

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);
Code
Loading...

Please log in to post a comment

Log in with GitHub

Community 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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License