Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Age Calculator with React, TS, and Tailwind

@betaluis

Desktop design screenshot for the Age calculator app coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


I wrestled with this one for a few days trying to understand the logic to calculate the age of an input and also crossing all the T's when it came to validation. I may have made it a little more complicated than it should have, but in the end, I'm happy with the results and functionality of the app.

In this challenge I wanted to practice managing state for an array of objects, so I made each input an object containing a timeframe with either "day", "month", or "year" as one key value pair, and the value of the input for each as another key. E.g. { timeFrame: "day", value: "2" }. Stored all three in an array and managed the state of this as it was changed, submitted, and validated.

Throughout the app I'm using a whole bunch of "if" statements. I feel like I was checking for each possible outcome (see "src/hooks/useValidation.tsx"). Is this a normal approach, or should I seek to avoid using so many if statements and optimize the logic?

Overall, the project was fun and challenging. I incorporated some of my own styles and features, so if you have any input or feedback, please share.

Community feedback

Please log in to post a comment

Log in with GitHub
Discord logo

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