18. DRY Penguins


#1


I passed the exercise but the console displays only { }....shouldnt it display "Hi my name is...."?


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

function Penguin(name) {
    this.name = name;
    this.numLegs = 2;
};

Penguin.prototype = new Animal();


#2

no, we only told Penguin class to inherit methods and properties from Animal.

So now the we have our penguin class, we can start creating actually penguins:

penguin1 = new Penguin("Captain hook")

since Penguin inherits from Animal, we have access to the sayName method:

penguin1.sayName();

#3

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