Dry Penguins. What is wrong?


#1


What is wrong with the code below? Why is the numLegs coming back as undefined?


https://www.codecademy.com/courses/objects-ii/3/3?curriculum_id=506324b3a7dffd00020bf661#

Oops, try again. The Penguin constructor should always set this.numLegs to 2. The constructor should only take a single parameter!


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

// define a Penguin class
function Penquin( name ) {
    this.name = name;
    this.numLegs = 2;
}

// set its prototype to be a new instance of Animal
Penguin.prototype = new Animal();


#2

You forgot to add numLegs to the functions parenthesis. The parenthesis needs to look like what you already did above.


#3

I found the issue... Penguin is not Penquin.


#4

Oh fair play didn't even notice that.


#5

If it wasn't for you separating my code into small chunks like that, I may have never found it. Thank you.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.