My Code Passes, But it is Incorrect (It's all in the Genes)


#1

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(animal) {
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();

I pass, but nothing is printed to the console but this error: TypeError: Cannot read property 'name' of undefined
Possible bug?


#2

You could replace Animal.name with this.name


#3

I have the same problem.My code is almost the same,and still when I type Animal.name it passes but console gives me an error.If I change Animal.name to this.name - it will pass without any errors but there will be no text in the console.Maybe this is really a bug?Or we're doing something wrong?


#4

Hi,

// create the sayName method for Animal
Animal.prototype.sayName = function(animal) {
console.log("Hi my name is " + animal.name);
};

Its not needed to type function(animal) change that into function()
And change console.log("Hi my name is " + animal.name); to

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

And everthing is working fine.

Best Regards
DooKoo


#5

Well,I've changed this already - but there is still no text in the console


#6

You are right it is a Bug.

Different Browser and refreshing the Site shows me it is a Bug!
Sometimes i see the text and sometimes with same code not!!!