Everything working the way it was supposed to


#1

Help please

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

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

There's a problem,
I used this code, everything working the way it was supposed to. However, it showed this error next to the "save and submit button":
Oops, try again.
When checking rabbit1, your code caused the following error: TypeError: rabbits[i] is undefined


Am I supposed to get "undefined" in lesson 25?
#2

The above line does not belong inside the constructor function. Remove.

Unclear where that error is coming from, It implies a loop iterator. Perhaps it is related to errant line mentioned above.


#3

ok, I fixed it. I forgot to put "new" in front of rabbit when using the constructor. Thanks for your help.

var rabbit1 = new Rabbit("fluffy");
var rabbit2 = new Rabbit("happy");
var rabbit3 = new Rabbit("sleepy");


#4

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