I am trying to print the age of the person but the console outputs invalid date. I have tried to put the birthday in without quotation marks but then it prints
birthday: 1969-12-31T23:59:58.000Z
class Person {
constructor(firstName, lastName, dob) {
this.firstName = firstName;
this.lastName = lastName;
this.birthday = new Date(dob);
}
greeting() {
return `Hello there ${this.firstName} ${this.lastName}`;
}
calculateAge() {
const diff = Date.now() - this.birthday.getTime();
const ageDate = new Date(diff);
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
}
const jack = new Person('Jack', 'Jones', '11-22-1993');
console.log(jack.calculateAge());