It's all in the Genes


#1

Hello, everyone in this section I got the green pass "Start Next Lesson" but in my console it says "TypeError "Hi my name is" is not a function" What did I do wrong? Why does the exercise seem to think I did it right. here's 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" (Animal.name));
}

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


#2

Animal does not have a property, name, only the instances of the class get that attribute from the constructor's this object.

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

#3

When I do that I get an error
// 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();

"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"


#4

I fixed the example to include a space in the string. Try that.


#6