check if over 18 javascript
function isOver18(dateOfBirth) { // find the date 18 years ago const date18YrsAgo = new Date(); date18YrsAgo.setFullYear(date18YrsAgo.getFullYear() - 18); // check if the date of birth is before that date return dateOfBirth <= date18YrsAgo; } isOver18(new Date("1999-12-01")); // true isOver18(new Date("2020-03-27")); // false
Here is what the above code is Doing:
1. It creates a new Date object called date18YrsAgo.
2. It sets the year of date18YrsAgo to be 18 years ago.
3. It checks if the date of birth is before the date 18 years ago.
The Date object has a setFullYear() method that sets the year of a date.
The Date object also has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has a getFullYear() method that gets the year of a date.
The Date object has