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>
JavaScript Class Method
Pass a parameter into the "age()" method.