ReferenceError: Penguin is not defined (19. Black (and White) Penguin Magic


#1

// 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 Animal(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 ("dog");
penguin.sayName();

The error messages.>
Oops, try again. Make sure your Penguin constructor is in working order. Your code threw the following error: ReferenceError: Penguin is not defined

`
I don't know why this error message keep coming ? Please help !!


#2

this class should be called Penguin and not Animal,

should be,

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

#3

I got it, thanks, bandit :grinning:


#4

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