[16/30] Code works but won't count as correct


#1

I have this 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();

When it is run, It logs this to the console:

Hi, my name is Captain Cook

But I get this error and can't continue.

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's wrong with my code? Thanks in advance.


#2
you use

Hi, my name is Captain Cook

Oops message

'Hi my name is [name]'


#3

I actually had to write this in the wrong way for it to work. I am pretty sure the way that you have it written is actually the correct syntax, but here is what I had to write:

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

Hope this helps you.


#4

take out the comma after the Hi.
it should be: console.log("Hi my name is "+this.name);
and not console.log("Hi, my name is "+this.name);


#5

It works! This is just what I needed help with, thanks!