16 animal not defined


#1

I am getting a animal not defined error. Any ideas?

// create your Animal class here
function animal(name, numLegs){
animal.name = name;
animal.numLegs = numlegs;

}

// create the sayName method for Animal
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

Hi your code is fine try to refresh the page.


#3

this didn't work for me.


#4

Try this

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

#5

there is a uppercase missing


#6

@wizmarco My code like yours,but it still can't work! It returns me the message is "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 can I do?


#7

Hi the error that you got say that the string is not right so try that

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

#8

Thank you! I have resolve!