| Not sure if this is a place to ask this but if someone does not have experience working with Javascript, they might have trouble reasoning about this code: https://codesandbox.io/s/is849 edit: complete code ```typescript class Person
{
id: number;
name: string;
yearOfBirth: number; constructor(id: number, name: string, yearOfBirth: number) {
this.id = id;
this.name = name;
if (yearOfBirth < 1900 || yearOfBirth > 2020) {
throw new Error("I don't understand you. Go back to your time machine.");
} else {
this.yearOfBirth = yearOfBirth;
}
}
getAge(): number {
const currentDate: number = new Date().getUTCFullYear();
return currentDate - this.yearOfBirth;
}
}class Dog
{
id: number;
name: string;
yearOfBirth: number; constructor(id: number, name: string, yearOfBirth: number) {
this.id = id;
this.name = name;
if (yearOfBirth < 1947 || yearOfBirth > 2020) {
throw new Error("I don't understand you. Go back to your time machine.");
} else {
this.yearOfBirth = yearOfBirth;
}
}
getAge(): number {
const currentDate: number = new Date().getUTCFullYear();
return (currentDate - this.yearOfBirth) * 7;
}
}const buzz: Person = new Person(1, `Buzz`, 1987); const airbud: Dog = buzz; console.log(`Buzz is ${buzz.getAge()} years old.`); console.log(`Airbud is ${airbud.getAge()} years old in human years.`); ``` |