I think my problem is easy to solve but I just can't get the hang of it. I want a function, which checks if the person is turning 18 in the current year, but the person doesn't have to be already 18 at the moment of checking.
Example: "Mike turns 18 next week". So he's still 17 today, but the function should return true, because he's turning 18 this year. If Mike turns 18 in the next year, the function should return false.
This is what I got so far, but this function only checks if the person is already 18 or not.
dateString = "2000-02-23" // person is 17 but turns 18 next week, so function should return true
otherDateString = "2001-01-13" //person is also 17, but function should return false, because this person just turnt 17 this year and will turn 18 next year
calculateAge(dateString) {
let birthday = new Date(dateString);
let ageDifMs = Date.now() - birthday.getTime();
let ageDate = new Date(ageDifMs); // milliseconds from epoch
let age = Math.abs(ageDate.getFullYear() - 1970);
console.log(age);
if (age>=18)
return true;
}
How do I have to change the function to just check if the person is turning 18 this year, no matter if the person is still 17 yet?