19. Black (and White) Penguin Magic


#1


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

I dont know what to do, always appears this: Make sure to create a new instance called Penguin penguin! I do not know what I'm missing, please someone help me!,The funny thing is that the console display appears: Hi my name is Pingo, all right, but still appears error


// the original Animal class and sayName method
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 Penguin(name, numLegs) {
    this.name=name;
    this.numLegs=2;
};
// set its prototype to be a new instance of Animal
Penguin.prototype.sayName = function () {
    console.log("Hi my name is " + this.name);
};
Penguin.prototype = new Animal();
var penguin = new Animal("Pingo", 2);
penguin.sayName(penguin);


#2

ok.. this work with me..

// the original Animal class and sayName method
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 Penguin(name) {
this.name = name;
this.numLegs = 2;
};

// set its prototype to be a new instance of Animal
Penguin.prototype = new Animal();
var penguin = new Penguin("juan");
penguin.sayName();


#3

new Penguin(...)

The numLegs property is inherited from Animal, and set in the definition so we don't need this as a parameter.


#4

hi guys, thank you to @cancalatrava and @mtf , its works when I took out the Animal by Pinguin and the number 2,thanks!