17. Marching Penguins - what is wrong?


#1


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;
    this.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();

it says "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 respectivel"

It logs name as undefined


#2

Well, it seems this.name is undefined for penguin. Lets see, where do you create this.name:

function Penguin (name, numLegs) {
    this.name;
    this.numLegs
};

you declared the variable, but didn't give them any values?


#3

right :wink: i looked at this many of time and didn't noticed that, thx


#4