Error: this is not a function


Hello there!

My code below:

// create your Animal class here
function Animal (name,numLegs) { = name;
this.numLegs = numLegs;

// create the sayName method for Animal
Animal.prototype.sayName = function() {
console.log("Hi my name is " +;
Animal.prototype.numLegs = function () {
console.log("My numlegs is "+ this.numLegs);

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

I receive this message and I can't solve it :slight_smile:
TypeError: penguin.numLegs is not a function


this.numLegs = numLegs So I think there is a conflict with a prototype called numLegs. Try changing your Animal.prototype.numLegs to Animal.prototype.sayLegs. Also change your call to the function accordingly.


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