16. Its All In The Genes


#1

// 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 (a) {
console.log("Hi my name is" + " " + a.name);
};

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

i submitted this code and it success, but it shows "TypeError: Cannot read property 'name' of undefined" on the console.. can somebody tell me what's going on?


#2

Try changing this part to this.name at the end instead of a.name


#3

yeah i know.. but it seems like my code above still can pass the exercise although it shows error on the console.. which is quite confusing for me


#4

Must be a small bug, try contacting codecademy


#5

console.log("Hi my name is"+" "+[this.name]);

Once try above statement.


#6

Thank you so much for the help with this.