Design comparison
SolutionDesign
Solution retrospective
Im happy
Community feedback
- @iamtridwanPosted 11 months ago
Hi @LARYEA LARYEA, great work you've done. i love how you worked on the implementation for validating the input fields for the month and days. I think there can be improvement tho, most especially in the area of calculating the age. you can simply do this by using using the code snippet.
const timeDiffInMil = new Date().getTime() - new Date(forminputs).getTime() const years = Math.floor(timeDiffInMil / 31556952000); const month = Math.floor((timeDiffInMil % 31556952000) / 2629746000) const days = Math.floor(((timeDiffInMil % 31556952000) % 2629746000) / 86400000)
This is an explanation of the code
- Get the difference in milliseconds between todays date and the input value of users. 2.calculate for the number of years by dividing the difference with 31556952000 which is the total milliseconds in a year and round it up to the nearest whole number(i.e math.floor)
- calculate for the month by dividing the remainder from the calculation of step above with 2629746000 which is the number of milliseconds in a month and rounding it off as well
- lastly we calculated the number of days by dividing the remainder gotten from the step above by 86400000 and the round it up. Hope this help. You can reachout to me if you need any assistance on X @iamtridwan
1 - @LaryeaNiiPosted 11 months ago
@iamtridwan thank you for the feedback. I have made the changes and it works so much better now!
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