Create a Method on an Object

Create a Method on an Object
0.0 0

#1

Tell us what’s happening:

Your code so far


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

dog.sayLegs();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/create-a-method-on-an-object


#2

Hi, the problem is your ‘sayLegs’ is doing a bit too much for this exercise.
Here’s what the exercise says it wants:
Using the dog object, give it a method called sayLegs. The method should return the sentence “This dog has 4 legs.”

But your code is adding the dog.name as well as the sentence requested. Simplify and it should pass the test.

good luck!
./H.B.