You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now make the Mole respond in a slightly more interesting way.
mole.js
Update the Mole's element to be initially invisible
Define an instance method on the Mole named show that makes the
mole appear
Update the Mole's "click" event handler to hide the Mole again
main.js
Call show on the Mole instance after you've inserted its element
into the DOM
The Mole class now needs a custom function (sometimes called a "method").
Remember: a class is a "template" or "mold" for creating objects. This
means that we can attach the show method to the Mole class, and all the moles we create will share it.
But I don't want to just give you the solution, so I'll update the "Car" class
from earlier:
functionCar(){this.wheels=4;}// The `Car` class has a property named "prototype". Anything we attach to that// object will be defined on the `Car` instancesCar.prototype.beep=function(){// Inside an "instance method" like this one, `this` refers to the car// instanceconsole.log('I am a car! I have '+this.wheels+' wheels! Beep beep!');};
// Later, when we've created a `Car` instance...varthirdCar=newCar();// It has a "beep" method that we can call!thirdCar.beep();
The text was updated successfully, but these errors were encountered:
Now make the Mole respond in a slightly more interesting way.
mole.js
Mole
's element to be initially invisibleMole
namedshow
that makes themole appear
Mole
's "click" event handler to hide the Mole againmain.js
show
on theMole
instance after you've inserted its elementinto the DOM
The
Mole
class now needs a custom function (sometimes called a "method").Remember: a class is a "template" or "mold" for creating objects. This
means that we can attach the
show
method to theMole
class, and all themole
s we create will share it.But I don't want to just give you the solution, so I'll update the "Car" class
from earlier:
The text was updated successfully, but these errors were encountered: