Create a Method on an Object with template literals

Tell us what’s happening:

I am using template literals from ES6 to solve this, but it somehow it doesn’t seem to work.

Your code so far


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

console.log(dog.sayLegs());
//Output: This dog has ${dog.numLegs} legs.

console.log("This is a dog. His name is ${dog.name}.")
//Output: This is a dog. His name is ${dog.name}.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 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

Ah ok, for template literals I have to use ` ` instead of " " or ’ '.

if you are wanting to go full es6, try doing this for sayLegs:

() => `This dog has ${dog.numLegs} legs.`

Since there is only one line and it is just directly returning the string, you don’t need either the brackets or the return.