Question about It's All in the Genes


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/objects-ii/3/1?curriculum_id=506324b3a7dffd00020bf661#

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Code behaves correctly, but I wasn’t sure why we have to have this.name interpolated in the sayName prototype. Why can’t it be (console.log("Hi my name is "+name);?

```

// 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 "+ this.name);
};

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

<do not remove the three backticks above>

#2

variable scope, name would be a undefined variable

this question explained this perfectly:


#3

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