Black (and White) Penguin Magic


#1

According to the code given bleow, It should print the penguin name in the output screen but there in no output....Why???

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


#2

Codecademy environment is quite buggy and laggy. Try to execute your code in the different environment, example -> https://repl.it/DN4a.

Output of your code is:

Hi my name is jack

#3

Again thankyou....:slight_smile:


#4

You're very welcome, again :slight_smile:


#5

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