Age Calculator [SCSS | MVC | Date-fns | Parcel]
Design comparison
Solution retrospective
I built this originally as a single js file. And I think that was totally acceptable for what this is. That being said, I wanted to hone my MVC skills. So I built it, and then refactored it into an MVC pattern. Nothing crazy, but was just good overall practice.
What challenges did you encounter, and how did you overcome them?Freaking Dates. The main area that I really spent the most time trying to solve, was getting the dates (year, month, day) calculations accurate. I know, in general, Dates are a pain in the butt to work with, and typically just converting everything to a ms format is a decent approach. But I did not want to do that.
Instead I used the isBefore, differenceInDays, differenceInMonths, & differenceInYears methods. After reading documentation on how they work, I learned while they do save sometime, they still have limitations. Especially since the difference methods round down to the whole (month, date, year).
Iterating through some ideas, I ended up deciding that they would work as-is for year & month calculations, but days required a bit more logic.
Community feedback
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