25: Constructors in review


#1


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


Oops, try again. When checking rabbit1, your code caused the following error: TypeError: rabbits[i] is undefined


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

var rabbit1 = new Rabbit1(fluffy);
var rabbit2 = new Rabbit2(happy);
var rabbit3 = new Rabbit3(sleepy);
rabbit1.describeMyself();
rabbit2.describeMyself();
rabbit3.describeMyself();


#2

The name of the class is Rabbit. Your instances are not invoking the constructor by the correct name.


#3

Can you update the code please?


#4

There are two general errors in the OP, and I just pointed out one of them.


#5

Are you passing strings?


#6

Below is the updated code making "rabbit" into "Rabbit".
Error message has changed to:
Oops, try again.Make sure you created rabbit1, rabbit2 and rabbit3

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

var Rabbit1 = new Rabbit1(fluffy);
var Rabbit2 = new Rabbit2(happy);
var Rabbit3 = new Rabbit3(sleepy);
Rabbit1.describeMyself();
Rabbit2.describeMyself();
Rabbit3.describeMyself();


#7

That hasn't fixed anything. Both errors are still present. What is the name of the constructor? Are the arguments supposed to be variables or strings?

function Foo(bar) {
    this.bar = bar;
}

var foo = new Foo("bar");

console.log(foo.bar) // bar

#8

Error message: Oops, try again. Make sure you created rabbit1, rabbit2 and rabbit3
updated code:
function Rabbit(adjective) {
this.adjective = adjective;
this.describeMyself = function() {
console.log("I am a " + this.adjective + " rabbit");
};
}

var Rabbit1 = new Rabbit1("fluffy");
var Rabbit2 = new Rabbit2("happy");
var Rabbit3 = new Rabbit3("sleepy");
console.log(Rabbit1.describeMyself());
console.log(Rabbit2.describeMyself());
console.log(Rabbit3.describeMyself());

    Save & Submit Code



Reset Code

#9

You are still missing the biggest mistake, and I've already pointed it out, twice.


#10

I keep thinking I have corrected the errors you suggest. Twice! Evidently I am not keying in on my error. I will go back and review loops and constructors then return to this specific task. Thank you for your help, LO


#11

Hint: All three rabbits use the same constructor.


#12

Thanks, it helped!
figured it out finally.


#13

2 posts were split to a new topic: Rabbits make me mad


#14