16. It's All In The Genes



For some reason, even though this does print the penguin's name onto the console, and I've followed the directions of the lesson I keep getting the error code "It looks like your Animal.prototype.sayName method does not properly log to the console 'Hi my name is [name]' where [name] is the name of the Animal."

// create your Animal class here
function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
// create the sayName method for Animal
Animal.prototype.sayName = function() {
console.log("Hi my name is " + penguin.name);

// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);

Replace this line with your code.


Use the build in context, this instead of penguin so the method will work for all instances. It is in the prototype, after all.


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