
Solution retrospective
i couldn't figure out how to display the current month and days of age so i showed instead the total months and days someone lived cant wait to see other people code and figure it out thank you i could finish this up cleanly but im challenging myself to keep everything vanilla js css and html
Please log in to post a comment
Log in with GitHubCommunity feedback
- @manjubhaskar02
Try this one .
function calculateAge(event) { event.preventDefault(); const birthdateInput = document.getElementById('birthdate'); const resultElement = document.getElementById('result'); const birthDate = new Date(birthdateInput.value); const currentDate = new Date(); let years = currentDate.getFullYear() - birthDate.getFullYear(); let months = currentDate.getMonth() - birthDate.getMonth(); let days = currentDate.getDate() - birthDate.getDate(); // Adjust negative months or days if (days < 0) { months--; days += new Date(currentDate.getFullYear(), currentDate.getMonth(), 0).getDate(); } if (months < 0) { years--; months += 12; } //and display the result.
Marked as helpful - @winston9797
Update : thanks to @manjubhaskar02 I was able to fix the issue with the app and display accurate data this community is awesome
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