Constructors in Review...HELP


#1

https://www.codecademy.com/en/courses/spencer-sandbox/3/6?curriculum_id=506324b3a7dffd00020bf661

My code is saying to make sure I have created rabbit1, rabbit2, and rabbit3. I already did... WHAT'S WRONG?!?!?!

function Rabbit(adjective) {
    this.adjective = adjective;
    this.describeMyself = function() {
        console.log("I am a " + this.adjective + " rabbit");
        
var rabbit1 = new Object();
this.adjective = fluffy;

var rabbit2 = new Object();
this.adjective = happy;

var rabbit3 = new Object();
this.adjective = sleepy;
}
 };

#2

console.log(Rabbit.describeMyself);

This is at the bottom.


#3

We need to invoke the method on all three objects.

console.log(rabbit1.describeMyself());

#4

I added that in, but it is still telling me to create rabbit1, rabbit2, and rabbit3.


#5

This is the bigger issue. Remove all of it from the constructor function. Invoke the constructor with one argument:

var rabbit1 = new Rabbit("fluffy");

Likewise for other two.


#6

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

var rabbit1 = new Rabbit("fluffy");

var rabbit2 = new Rabbit ("happy");

var rabbit3 = new Rabbit ("sleepy");
}
};

// now we can easily make all of our rabbits

console.log(rabbit1.describeMyself());

My code now looks like this. What you said made sense because it wasn't at all linked to the original Rabbit function. I still get the same error message though. It says exactly "Oops, try again. Make sure you created rabbit1, rabbit2 and rabbit3"


#7

in the box, it also says "ReferenceError: rabbit1 is not defined".


#8

Move them outside of the constructor function.

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

#9

Yes!!! It worked!! Thank you so much!! :slight_smile:


#10

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