"Type Error:" but tells me to continue anyways


#1

https://www.codecademy.com/en/courses/objects-ii/3/1?curriculum_id=506324b3a7dffd00020bf661

I don't know if there is anything wrong with the code b/c it tells me to start a new lesson. But I get a Type Error as you will see if you copy and paste the code below on to the link.

Just want to know if it's correct or if there is something wrong. :confused:


// 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(sn) {
    var names= "Hi my name is" + sn.name;
    console.log(names);
    };




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


#2

Yes, there is something wrong. Add one console.log statement to the sayName method and you should be able to find the problem:

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

And answer this question - where is stored the name of the animal?


#3

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