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);