What is wrong with my code?


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

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

What is wrong with my code?
It says “Oops, try again. When checking rabbit1, your code caused the following error: TypeError: undefined is not an object (evaluating ‘rabbits[i].adjective’)”


More Options
#2

Remember to use new when declaring an instance.


#3

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