16, Its all in the genes


#1



Link to my code


My code passes with both this.name and sayName in ("Hi my name is " + this.name/sayName); I get no output when using this.name and when I use sayName I pass the lesson but get error code "ReferenceError: sayName is not defined". Could anyone explain what the correct form would be and maybe why I am not getting an output? Thanks!

// 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 " + sayName);
};

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


#2

We need to refer to the context object (the instance), this.

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

#3

A post was split to a new topic: I have a problem in my code