Constructors in Review


#1

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

// now we can easily make all of our rabbits
var rabbit1 = new constructorName(objectName.methodName);`
ReferenceError: constructorName is not defined


#3

And Constructor name is obviouslt not defined...... The constructor name is Rabbit.. So its suppose to be like this

var rabbit1 = new Rabbit("Happy");

#4

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

// now we can easily make all of our rabbits
var rabbit1 = new Rabbit();
console.log("Fluffy");
var rabbit2 = new Rabbit();
console.log("Happy");
var rabbit3 = new Rabbit();
console.log("Sleepy");`
New code and now it says Make sure to give rabbit1 the adjective fluffy
What am i doing wrong?


#5

Help anyone please i dont know what i am doing


#6

Yeas @codeace40947 you put it Fluffy its suppose to be lowercase fluffy.


#7

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

// now we can easily make all of our rabbits
var rabbit1 = new Rabbit();
console.log("fluffy")
var rabbit2 = new Rabbit();
console.log("happy")
var rabbit3 = new Rabbit();
console.log("sleepy")
When i did that it still says Make sure to give rabbit1 the adjective fluffy


#8

When you define an object you dont say

console.log("fluffy")

Instead

rabbit1.describeMyself('fluffy')

#9

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

// now we can easily make all of our rabbits
var rabbit1 = new Rabbit();
rabbit1.describeMyself('fluffy')
var rabbit2 = new Rabbit();
rabbit2.describeMyself('happy')
var rabbit3 = new Rabbit();
rabbit3.describeMyself('sleepy')
Now it is saying I am a undefined rabbit
I am a undefined rabbit
I am a undefined rabbit


#10

Sorry erase what i just said. Your suppose to put it in your construcor like this:

var rabbit1 = new Rabbit('fluffy');

#11

I'm sorry I'm having a lot of trouble getting this one, I've tried following all the comments above, and tried a few different ways of constructing the code. My latest attempt is here, can someone tell me where I'm going wrong?

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

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

var rabbit2 = new Rabbit();
rabbit2.describeMyself("happy");

var rabbit3 = new Rabbit();
rabbit3.describeMyself("sleepy");

The response I received was...

Oops, try again. Make sure to give rabbit1 the adjective fluffy

Which I'm pretty sure I have!!


#12

OK.. disregard my previous post. This got me over the line, which is weird because I tried this same code a few times before and it Didn't work...

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

// now we can easily make all of our rabbits
var rabbit1 = new Rabbit('fluffy');

var rabbit2 = new Rabbit('happy');

var rabbit3 = new Rabbit('sleepy');

#13

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

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

u get output:
I am a fluffy rabbit
I am a happy rabbit
I am a sleepy rabbit


#14

Here is my code, hope to help somebody!!

var rabbit1 = new Rabbit ();
rabbit1.adjective = "fluffy"
rabbit1.describeMyself ("I am a " + rabbit1.adjective + " rabbit");

var rabbit2 = new Rabbit ();
rabbit2.adjective = "happy"
rabbit2.describeMyself ("I am a " + rabbit2.adjective + " rabbit");

var rabbit3 = new Rabbit ();
rabbit3.adjective = "sleepy"
rabbit3.describeMyself ("I am a " + rabbit3.adjective + " rabbit");


#15

and here is the result:


#16

This worked for me...but I don't understand exactly why I have to tell them that they are "fluffy" or "happy" twice. It seems like a waste or inefficient.

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

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


#18