Help on "Constructors in Review"


#1

Below is my code. It tells me that " When checking rabbit1, your code caused the following error: TypeError: Cannot read property 'adjective' of undefined".

  function Rabbit(adjective) {
    this.adjective = adjective;
    this.describeMyself = function() {
        console.log("I am a " + this.adjective + " rabbit");
    };
}

// now we can easily make all of our rabbits
var rabbit1 = new Rabbit1("fluffy");
var rabbit2 = new Rabbit2("happy");
var rabbit3 = new Rabbit3("sleepy");
rabbit1.describeMyself();
rabbit2.describeMyself();
rabbit3.describeMyself();

#2

There is just the one constructor function, Rabbit(). Use it in all three instances.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.