25/33 ... need help!


#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
function rabbit1(adjective) {
this.adjective = fluffy;
this.describeMyself = function() {
console.log("I am a " + this.adjective + " rabbit1");
};
}
function rabbit2(adjective) {
this.adjective = happy;
this.describeMyself = function() {
console.log("I am a " + this.adjective + " rabbit2");
};
}
function rabbit3(adjective) {
this.adjective = sleepy;
this.describeMyself = function() {
console.log("I am a " + this.adjective + " rabbit3");
};
}

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


#2

You're supposed to make the rabbits very easily in only 6 lines - using the Rabbit constructor.

Remember last lesson? The Person constructor:

function Person(name,age) {
  this.name = name;
  this.age = age;
  this.species = "Homo Sapiens";
}

Constructors make it very easy to create multiple objects with the same properties.
For example, you could make bob like this:

var bob = new Person("Bob",32)

You're telling it to create a new Person, bob, and make his age 32 and his name Bob.

Try it with the bunnies. If you still can't figure it out, I'll give you some hints.


#3

this is now what i have...

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 objectName = new rabbit1(value for each property);
console.log("I am a " + fluffy + " rabbit");

var objectName = new rabbit2(value for each property);
console.log("I am a " + happy + " rabbit");

var objectName = new rabbit3(value for each property);
console.log("I am a " + sleepy + " rabbit");

now what?


#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("fluffy");
var rabbit2 = new Rabbit("happy");
var rabbit3 = new Rabbit("sleepy");

rabbit1.describeMyself();
rabbit3.describeMyself();
rabbit2.describeMyself();

This is a whole code to get it done. Really easy and no much writting when you get what code is asking you to do. I will explaion it to you right now.

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

This is our self made object that takes in only 1 variable called adjective.

this.adjective = adjective means that this 1 variable that we have is not defined here (example. with string or some value) because we will define it later when we need it.
purpose of it is that we can call her anywhare in our code later when we need her. Now she rests there unmarked from all values waiting for us to give her something.
this.describeMyself = function() {
console.log("I am a " + this.adjective + " rabbit");
};

Is just method in our self made object that will output text " I am a + adjective that we will give to our bunnies 1,2 and 3 later + rabbit.


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

This part of code that you need to write is:

  1. new variable called rabbit1, rabbit2, rabbit3
  2. new -> means the same thing is saids, you are creating something new
  3. Rabbit -> you are creating something new in our self made object that I showed above called Rabbit
  4. for rabbit1 you gave him atribute called "fluffy, rabbit2 got :"happy" and so on.....

Rabbit(adjective) above and now we are making **new** Rabbit("fluffy").

Time has arrived when we woke up our adjective and saved something new in it later here in a code.

Last thing needed!

rabbit1.describeMyself();
rabbit3.describeMyself();
rabbit2.describeMyself();

Here we called our new made variables (rabbit1,2 and 3) with our method which is inside our self made object.

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

Output of this call at the end of the code get us:

  1. "I am a fluffy rabbit"
  2. "I am a happy rabbit"
  3. "I am a sleepy rabbit"

P.S. I'm not the best teacher but I hope you understand even a little I just wrote here.