crop_rotate
Run
<!DOCTYPE html> <html> <body> <h2>JavaScript Class Method</h2> <p>Pass a parameter into the "age()" method.</p> <p id="demo"></p> <script> class Car { constructor(name, year) { this.name = name; this.year = year; } age(x) { return x - this.year; } } let date = new Date(); let year = date.getFullYear(); let myCar = new Car("Ford", 2014); document.getElementById("demo").innerHTML= "My car is " + myCar.age(year) + " years old."; </script> </body> </html>
PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCjxib2R5Pg0KDQo8aDI+SmF2YVNjcmlwdCBDbGFzcyBNZXRob2Q8L2gyPg0KDQo8cD5QYXNzIGEgcGFyYW1ldGVyIGludG8gdGhlICJhZ2UoKSIgbWV0aG9kLjwvcD4NCg0KPHAgaWQ9ImRlbW8iPjwvcD4NCg0KPHNjcmlwdD4NCmNsYXNzIENhciB7DQogIGNvbnN0cnVjdG9yKG5hbWUsIHllYXIpIHsNCiAgICB0aGlzLm5hbWUgPSBuYW1lOw0KICAgIHRoaXMueWVhciA9IHllYXI7DQogIH0NCiAgYWdlKHgpIHsNCiAgICByZXR1cm4geCAtIHRoaXMueWVhcjsNCiAgfQ0KfQ0KDQpsZXQgZGF0ZSA9IG5ldyBEYXRlKCk7DQpsZXQgeWVhciA9IGRhdGUuZ2V0RnVsbFllYXIoKTsNCg0KbGV0IG15Q2FyID0gbmV3IENhcigiRm9yZCIsIDIwMTQpOw0KZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoImRlbW8iKS5pbm5lckhUTUw9DQoiTXkgY2FyIGlzICIgKyBteUNhci5hZ2UoeWVhcikgKyAiIHllYXJzIG9sZC4iOw0KPC9zY3JpcHQ+DQoNCjwvYm9keT4NCjwvaHRtbD4=