16 Its all In Genes Reference Error!


#1


It passes the lesson but i get this error: ReferenceError: sayName is not defined in the box. why so?



ReferenceError: sayName is not defined


Replace this line with your 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() {
     this.name = sayName;
     console.log("Hi my name is" + [name]);
 }
// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();


#2

Do you think it should be? If so you'd need to reconsider the place where you think you do that.

If you don't think it should be, then why would it be complaining about that it isn't? Maybe your code is trying to use it somewhere even though it shouldn't exist.


#3

I mean why is the error appearing, whats wrong in code? and if theres something wrong in my code why is it letting me go to the next lesson?


#4

It says that some variable wasn't defined. Right? Why would it say that? It'd say that because you're trying to use the value of that variable - but it doesn't exist, so that's an error.
By reading the error message, you can tell which variable it is and what was done incorrectly to it. Since "sayName" occurs in 3 places you could then look at each such place and see if you can motivate why you'd be able to do what you do there. You can also do things like switch them out for other names or values and observing what effect that has and through that determine which one it is.
Judging by that you were trying to read a variable, you were trying to get at some information. You'd need to think about where that information exists, and to specify that location (because guessing won't make it "click", there's only one right place and when you're the one writing the code only you know where that is. so where did you put it?)


#6

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

just try this.


#7

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