I'm going through a JavaScript tutorial and it's asking me to create do the following:
Create a Penguin object with the variable name penguin and any name you'd like.
Then call penguin.sayName();.
My code is as follows:
// 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();
// Here's where I need to create the Penguin object
var penguin = {
name: "Pinguino"
};
penguin.sayName(name);
I'm fairly certain that my code is correct up to where I set the Penguin
prototype to the new instance of Animal
. However when I submit the code, I get an error saying "Make sure to create a new Penguin instance called penguin!"