16. It's All in the Genes


#1

Hi,

Here is my code:

// 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();

And this is what happens when I run the code:

Oops, try again. 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

What am I doing wrong?


#2

as simple as it is I think it's because the string prints

"Hi my name isCaptain Cook"

instead of

"Hi my name is Captain Cook"

//your version

//my fix

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

// a space after the word is before the " should work


#3

Wow! I would never have thought of that.

Thanks a lot!