Design comparison
Solution retrospective
Any criticism are welcome (especially for JavaScript) I think i did not account for the months that have 30 or 28 days and the leap year please help for what i missed thank you !
Community feedback
- @AnarenaaPosted over 1 year ago
Hello👋
I had the same problem with determining the last day of the month. You need to add one function:
//my version of variables let month = parseInt(document.getElementById('month').value); let year = parseInt(document.getElementById('year').value); function getDateInMonth(y, m) { return new Date(y, m, 0).getDate() //when you set the day argument to 0, it calculates the last day of the previous month }
Then inserting a function into calculations:
if (currentDate >= dobDate){ dAge = currentDate - dobDate } else { mAge-- dAge = getDateInMonth(year, month) + currentDate - dobDate }
I can give advice about the error class. You can style it with CSS instead of JS. Only in JS, you will need to add this class to the elements (or better, the container) at the time of the error, if everything is correct, remove it.
By the way, instead of
<h2>
, use<label>
for labels above the fieldsСSS
.error label { ... } .error input { ... } .error p { ... }
I hope to help😊
Marked as helpful1@NxumaloDevPosted over 1 year ago@Anarenaa Thank you so much. Apologies for responding so late didn't realise i never thanked you.
1
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