0
var firstQuestion = {
  question: "What does the heaviest cat in the world weigh?",
  answers: ["50lb", "20lb", "5lb", "70lb"],
  correctAnswer: this.answers[0]
}

I can't get correctAnswer to work. If I pull it out of the object, it works, but inside of the object, it won't refer to the array at all. What's the deal?

  • See the linked question's answers for details. One option is to make `correctAnswer` a *getter*: `get correctAnswer() { return this.answers[0]; }` You access that just like any other property, but it's actually a function which gets run on access. – T.J. Crowder Sep 02 '17 at 12:28
  • Yesss, thanks! That should work! Still trying to grasp "this" :| – its me amy Sep 02 '17 at 12:31

0 Answers0