I've just wrapped up this project, and I must say, your insights and contributions are truly invaluable.
Tridwan
@iamtridwanAll comments
- @jen67Submitted 11 months ago@iamtridwanPosted 10 months ago
Hi @jen67! I just went through your project now (both the live deployment and code)and i must say you really nailed it in the aspect of design specification as well as responsiveness. Great job. One thing i noticed tho, is with the functionality with the calculations. whenever i enter a date i get this continous calculation of number, which inturn makes the whole UI glitching giving a bad experience. A way to resolve this issue is to address the calculations for the age. one way to do that is as follows
- since we have the current date and the inputted date we can just convert them to milliseconds and get thier difference. below is a sample code
let ageInMilSec = new Date().getTime() - new Date(inputedDate).getTime()
the getTime method of the date object returning time in milliseconds 2. calculate the number of years in the remaining milliseconds. this can be done like so
const years = Math.Floor(ageInMilSec / 31556952000)
since there are 31,556,952,000 in a year. 3. calculate for the month as so:
const month = Math.floor((ageInMilSec % 31556952000) / 2629746000)
what we did was divide the remainder from what we got by dividing the age in milliseconds by the total miiliseconds in a year, by the milliseconds in a month 4. you can get that of the day by doing so
const day = Math.floor(((ageInMilSec % 31556952000) % 2629746000) / 86400000)
there are 86,400,000 in a day. so what we did was divide the result we get from the remainder of month divided by its own milliseconds. Hope this helps. if you have any further assistance or question you can reachout to me on @iamtridwan on X.
Marked as helpful0 - @LaryeaNiiSubmitted 11 months ago
Im happy
@iamtridwanPosted 11 months agoHi @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 - @akaahlSubmitted over 3 years ago
Hi, thanks for checking out my solution for this challenge. I built most of the features right, though I am still not quite satisfied when it comes formatting the number correctly, when arithmetic signs are clicked.
If someone could help point me in the right direction, I'd be extremely grateful.
Much thanks to all of you.
@iamtridwanPosted over 3 years agoGood job here. But I noticed the display for mobile is not suited for mobile devices. You could set the width using media query like so wrapper{ width:90%; margin: 10px auto; } the wrapper is the container for the calculator itself. Moreso the margin top and bottom could be optional or may be set to zero.
Marked as helpful0