Design comparison
Solution retrospective
Hello 👋
This is my solution to the age calculator app challenge. I built it all by myself, I'm still a newbie with JavaScript, my app is totally working but there are a lot of if
and else if
on my code, so I'm pretty sure there is a better way to do it, but honestly I don't know how.
Feedbacks are welcome
Community feedback
- @RafaelSS427Posted about 1 year ago
Hi Alessandra, you did a great job! These are my observations about your code.
- For the declaration of variables it is recommended to use "const" or "let". "var" is rarely used nowadays.
- The date validations are not entirely correct, for example, the entry for 02-31-2000 should be wrong. I recommended the use of date object for this. For example, you can use the date object to validate if the day is correct and thus avoid complex validations with conditional operators.
const userDate = new Date(`${month}-${day}-${year}`) if (userDate.getDate() !== Number(day)) { throw Error('Must be a valid day') }
When we enter an invalid date to a date object, it will add the days to the next month as a result, so if we do something like this "new Date("02-31-2023")" we would have this as the answer: "2023-03-03T06:00:00:00.000Z".
- I recommend leaving the max-width with the value "auto". This way it is centered on all devices.
body{ display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; /* max-width: 1450px; It's not necessary */ background-color: hsl(0, 0%, 94%); font-size: 2rem; }
Marked as helpful1@itsale-oPosted about 1 year ago@RafaelSS427 True, I totally forgot to consider february and its 28 days, I'll fix that. Also, I will test the date object the way you suggested.
Thank you for the feedback, it was very helpful!
0
Please log in to post a comment
Log in with GitHubJoin 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