17. Marching Penguins


#1

Here is my code:

function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

// create a Penguin constructor here
function Penguin ("bob",2){
this.name = name;
this.numLegs = numLegs;
};

// create a sayName method for Penguins here
Penguin.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

// our test code
var theCaptain = new Penguin("Captain Cook", 2);
theCaptain.sayName();

The error states there is a problem with my syntax.
I am lost, can some please help me.
Thanks in advance


#2

@tyron180,

Have a close look at....
// create a Penguin constructor here

function Penguin ("bob",2){

this.name = name;
this.numLegs = numLegs;
};


#3

Error: Oops, try again. It looks like your Penguin constructor doesn't properly take in two parameters and save them as this.name and this.numLegs respectively

function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
};
Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

// create a Penguin constructor here
function Penguin(name, numLegs){
this.name = name;
this.numlegs = numLegs;
};

// create a sayName method for Penguins here
Penguin.prototype.sayName= function(){
console.log("Hi my name is " + this.name);
};

// our test code
var theCaptain = new Penguin("Captain Cook", 2);
theCaptain.sayName();
var rocky = new Animal("Rocky", 4);
rocky.sayName();

i couldn't understand about the error message...


#4

comment this out and try again


#5

@p31260

Have a close look at

this.numlegs


#6

@p31260,

penguin with only a Animal prototype sayName method defined

http://www.codecademy.com/forum_questions/55a1ff5b9113cb0df10005f4#comment-55a3119e937676536e0005ea


#7

this.numlegs = numLegs; case sensitive you have a "l" instead of "L"


#8

function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

// create a Penguin constructor here
function Penguin(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
// create a sayName method for Penguins here
Penguin.prototype.sayName= function(){
console.log("Hi my name is " + this.name);
};

// our test code
var theCaptain = new Penguin("Captain Cook", 2);
theCaptain.sayName();