16. It's all in the Genes....passed lesson but still no log displaying


#1


I passed the test but the errormessage says
TypeError: Cannot read property 'name' of undefined


function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
};

Animal.prototype.sayName = function() {
    this.name = name;
    console.log("Hi my name is " + Animal().name);
};

var penguin = new Animal("Captain Cook", 2);
penguin.sayName();


#2

Ok so at least for me when I add this.name = name into my prototype function I get this error: 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

So basically, i don't know why you would need to print this again under the prototype when you already have it in the function Animal so get rid of it! That should solve your problem since that is the only difference I can see between mine and yours!


#3

Thank you! I already tried it out without this.name...but the error message stays the same :confused:


#4

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

what is Animal().name ?

you should use this.name

and of course you dont need this.name = name; again what @bibleman13 said


#5

Thanks...the errorcode is not showing anymore...but why doesnt it log into the console? My console stays empty


#6

can i see your code?


#7

function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
};

Animal.prototype.sayName = function() {
console.log("Hi my name is " + this.name);
};

var penguin = new Animal("Captain Cook", 2);
penguin.sayName();


#8

try after refreshing your browser


#9

^^ ok it worked -_^ thanks


#10

most welcome :slight_smile:
hope you've understand everything :slight_smile:


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.