I would like some constructive feedback
I am currently doing the Frontend Mentor Challenge "Age Calculator" (https://www.frontendmentor.io/challenges/age-calculator-app-dF9DFFpj-Q) and I'd appreciate some constructive feedback about my CSS and JavaScript: https://codepen.io/lena-s98/pen/GRPGXOe
But please avoid opinionated feedback like "Don't use comments", etc ...
I'm struggling to get the age calculation to work correctly. Maybe someone can nudge me into the right direction 🙂
Frontend Mentor
Frontend Mentor | Age calculator app coding challenge
This challenge is designed to sharpen your JavaScript and form validation skills. Working with dates in JavaScript can be tricky, so this will be a nice test!
10 Replies
whats wrong with the calculation
seems to calculate it fine
When I use my birthdate it's one month off for example. And when you use the current month 10 then it breaks completly 😅
and it's kinda hard for me to figure out what to do about it.
Oh for that i'd use absolute time rather than trying to get the month day and year separately
lemme just try something
I thought about doing that but then decided to do each seperately
the code you have is unnecessarily complicated for one. I'd save month/day relations in an array/object first. then you could replace all your ifs with
months[monthValue] === 31
or appropriate month day counts
then you'd borrow days from previous month and decrease month count
and do similar thing with years.
@lena_neko@MartynasXS oki I'll look into implementing it that way. thank you
also here
you dont check if months are equal
you can just change < into <= in the first if statement
I see. Fixed it 🙂
as for css im no expert but it looks nice visually so i wont question anything.