This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.
Smartphone icons created by Freepik - Flaticon
In a JavaScript Class you cannot use variable without declaring it.
class Car { constructor(name, year) { this.name = name; this.year = year; } age() { // date = new Date(); // This will not work const date = new Date(); // This will work return date.getFullYear() - this.year; } } const myCar = new Car("Ford", 2014); document.getElementById("demo").innerHTML = "My car is " + myCar.age() + " years old.";