Creating a method on an object

Creating a method on an object
0.0 0

#1

Can someone take a look at this and tell me why I can’t get my code to properly return sayLegs.

let dog = {
  name: "Spot",
  numLegs: 4,
  sayLegs: function () {return 'This dog has  ' + dog.numLegs + 'legs.';}
};

dog.sayLegs();

#2

I’m guessing that you just need to check the formatting of the message that comes out. Is all the spacing, capitalization, spelling, and punctuation correct?


#3

try that

function dog(name, numLegs) {
this.name = name,
this.numLegs = numLegs,
this.sayLegs = function () {return 'This dog has '+ this.numLegs + ‘legs.’;};
};

let spot = new dog(“Spot”, 4);
console.log(spot.sayLegs())


#4

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.