Frustrated - Object Constructor


#1

I have no idea what the ■■■■ I'm doing and I'm about to just quit coding honestly. anyways heres the code:

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

var rabbit1 = new Rabbit(adjective);
        this.adjective = "fluffy";
        console.log("I am " + this.adjective + " rabbit1");   
var rabbit2 = new Rabbit(adjective);
        this.adjective = "happy";
        console.log("I am " + this.adjective + " rabbit2");
var rabbit3 = new Rabbit(adjective);
        this.adjective = "sleepy";
        console.log("I am " + this.adjective + " rabbit3");

error message:

Make sure to use the Rabbit constructor when creating rabbit1

and instruction:

Create a new object rabbit1 with the adjective "fluffy", a new object rabbit2 with the adjective "happy", and a new object rabbit3 with the adjective "sleepy".

Use the method describeMyself to print out in the console a sentence about each object you just created!

any help would be very appreciated, thanks.


#2

Instead of this:

var rabbit1 = new Rabbit(adjective);
        this.adjective = "fluffy";
        console.log("I am " + this.adjective + " rabbit1");

First create a new fluffy rabbit like this:

rabbit1 = new Rabbit("fluffy");

Then you can get rabbit1 to describe itself like this:

rabbit1.describeMyself();

25.) rabbit1 does not have an adjective
#4

Thanks a million, that worked


#5

Thanks for this. In my code I was writing:

console.log(rabbit1.describeMyself());

Which Codecademy "passed," but in the output it read:

"My name is Fluffy!
undefined
My name is Happy!
undefined
. . ."

And seeing your solution made me realize that you don't need the outer "console.log();" shell because the method already has a console.log(); written in it.


#6

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