Black (and White) Penguin Magic


#1

Whats wrong with my code? Its giving Syntax Error.

It asked me "Create a Penguin object with the variable name penguin and any name you'd like.Then call penguin.sayName();."

// 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 = new Animal();
Penguin penguin = new Object();
penguin.sayName();


#2

the error is in

Penguin penguin = new Object();

as you supposed to write:

var penguin = new Penguin("Billy or other Penguin's name");

delete the firts one and write the second one... :+1:


#3

thanks..it is working now.......