OOP -> Create a method on an Object: Arrow function should be accepted

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

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

dog.sayLegs();
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36

Challenge: Create a Method on an Object

Link to the challenge:

:grey_question:

Your code does not run due to malformed syntax. If you fix the syntax error, you’ll see why an arrow function doesn’t work here as you’ve written it.

this keyword behaves differently for regular and arrow functions; this is where your syntax error stems from

1 Like

Well, that and the misplaced ;

1 Like

right, i didnt even notice the semicolon; i went straight to the challenge and tried to solve with an arrow function and use this , which obviously didnt work.

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