@R3ygoski
Posted
Hello Joseph, your project turned out incredibly well, it's close to the proposed design, and has a very unique theme. I also found it interesting that you already created a link between it and your Portfolio.
I also noticed that you used a neo-brutalism aesthetic for your homepage button, so it would be interesting to add this aesthetic to the calculator as well, to make it more cohesive. But that's just a suggestion.
Regarding your code, it's clean, but it doesn't seem to be correct because, for example, I entered 14/07/2001, and the result returned to me was "23 years, -3 months, 16 days". In this way, only the days are correct, while the month and year are not. What you can do is add a way so that when the month has a negative value, the year is reduced by 1.
Also, in your logic, you didn't include leap years, you can do this using the modulo operator to see if the year is divisible by 4.
Below is the code you can use to make the correct calculation (Note that only a small portion has been changed for this, and it was in the calculateAge function):
let yyyy = todaysYear - birthDate.getFullYear();
let mm = todaysMonth - birthDate.getMonth();
let dd = todaysDay - birthDate.getDate();
if (dd < 0) {
mm--;
dd += daysPerMonth[birthDate.getMonth()];
} else if (mm < 0) {
yyyy--;
mm += 12;
}
And again, congratulations, if you have any questions please comment below and I'll try to help as best as possible, and if something goes wrong with the code I provided, let me know as well.
Marked as helpful
@JreyIV
Posted
@R3ygoski
thanks for letting me know about the bug. I fixed it shortly after posting this so it should be working now. And yeah I honestly just had to be somewhere but wanted to get this up already so I didn't bother with the leap year. I'll definitely give it a shot some other time!