Black and White Penguin Magic


// the original Animal class and sayName method

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

// define a Penguin class
function Penguin(name) {
    this.numLegs = 2; = name;
Penguin.prototype = new Animal();
var penguin = Penguin("penguin");

// set its prototype to be a new instance of Animal

Note.Throwing an Error regarding Inheritence.
May be I was in wrong wrong direction.
Can any one post the correct that I can rectify my mistake.


this line:

var penguin = Penguin("penguin");

when you want to create an instance of your object, you need the new keyword:

var penguin = new Penguin("penguin");


Thank You .It worked