DRY Penguins


// 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();

It allow me pass but did not display any result. Why is it so? i Understand that the penguin class have inherit the Animal class. My result came out this way. Please can someone explain more.


This code gives no output, why would it give any output? The things you do here is creating classes (animal and penguin which inherits from animal) and a class instance.

What is displayed to user is only a very small percentage of code (in general, in your case no output)


okay. Thanks. I got more understanding of the exercise when i did the next exercise.


you're welcome :slight_smile: any questions about this exercise or the next one? Anything unclear?