This is a solution to the Age calculator app challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
- View an age in years, months, and days after submitting a valid date through the form
- Receive validation errors if:
- Any field is empty when the form is submitted
- The day number is not between 1-31
- The month number is not between 1-12
- The year is in the future
- The date is invalid e.g. 31/04/1991 (there are 30 days in April)
- View the optimal layout for the interface depending on their device's screen size
- See hover and focus states for all interactive elements on the page
- Bonus: See the age numbers animate to their final number when the form is submitted
- React - JS library
- Vite
- Tailwind CSS
This project took a while to complete starting from creating the functions to calculate the dates, the age, date validations, and errors. There were also many conditionals that were written and it took a while for figure out how to conditionally render the error messages. I also gained more knowledge in using Tailwind CSS and learning how to customize the sizing, understanding mobile first design, and implementing the break points.
To see how you can add code snippets, see below:
<div className="font-semibold text-s text-left">
{InvalidDay() || ErrorWhole() ? (
<span className=" text-rose-500">DAY</span>
) : (
<span className=" text-zinc-500 ">DAY</span>
)}
</div><div className="bg-white w-[343px] h-[486px] lg:w-[840px] lg:h-[680px] p-[25px] lg:p-[56px] rounded-t-[25px] lg:rounded-t-[40px] rounded-bl-[25px] lg:rounded-bl-[40px] rounded-br-[100px] lg:rounded-br-[200px]">
</div>function calBirth() {
if (isNaN(dateObj) || dateObj > d) {
return null;
} else {
setYears(Math.floor((totalDaysCurrent - totalYears) / 365));
setMonths(Math.floor(((totalDaysCurrent - totalYears) % 365) / 31));
setDays(Math.floor(((totalDaysCurrent - totalYears) % 365) % 31));
}
}Areas that I would like to continue develop is apply global css and use themes in Tailwind. I would like to improve the functionality of the date checker so that it automatically check the dates of the past correctly. I had to manually enter coding to make 4/31 return an error.
- Adding numbers in React - This helped me to be able to calculate the totalYears from useState. Before is would concatenate the numbers not producing the total years required.
- Date validations - This helped me to create the functions to check the dates for past and errors.
- Deploy React static app on Github - With this article, I was finally able to deploy a static React website on Github.
- Website - Heejung Hong
- Frontend Mentor - @heejung-hong
- LinkedIn - heejung-hong





