16. It's All In The Genes


#1


https://www.codecademy.com/courses/objects-ii/3/1?curriculum_id=506324b3a7dffd00020bf661#


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);
penguin.sayName();


Replace this line with your code.


#2

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


#3

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