Rabbit


#1

someone please help me to correct the error..

function Rabbit(adjective) {
this.adjective = adjective;
this.describeMyself = function() {
console.log("I am a " + this.adjective + " rabbit1");
console.log("I am a " + this.adjective + " rabbit2");
console.log("I am a " + this.adjective + " rabbit3");
};
}
var rabbit1=new Object
{
rabbit1.adjective="fluffy";
};
var rabbit2=new Object
{
rabbit2.adjective="happy";
};
var rabbit3=new Object
{
rabbit3.adjective="sleepy";
};
Rabbit(rabbit1);
Rabbit(rabbit2);
Rabbit(rabbit3);


#2

i understand..this is the correct one..

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");


#3

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

Whats wrong in this?
Please help me..

Thanks in advance.


#4

In your code, you created "Rabbit","rabbit1","rabbit2","rabbit3" all as a constructors,each constructor have one property and method,and there is no objects.
Rabbit is a constructor.we can create more objects using one constructor."rabbit1","rabbit2","rabbit3" all are objects.we need to create these objects using "Rabbit" constructor.
In this program, constructor have one property "adjective". and one method "describeMyself".if you want call your method use this syntax,
rabbit1.describeMyself();
rabbit2.describeMyself();
rabbit3.describeMyself();