19.Black (and White) Penguin Magic


#1


// 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 pengiun = new Penguin ("Pingo");
penguin.sayName();

I refreshed the page, and I don't see any mistake? any ideas?


#2

You define pengiun but use penguin. Typo.


#3

I just rewrote the same code and it worked, really weird..
thanks!


#4

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