1

Simple question, Provided that 'dish' is a standard object from the same type. Why is the push not possible??

 class DinnerModel {
  constructor() {
    this.menu = new Array();
    this.dishes = dishesConst;
    this.guests = this.setNumberOfGuests(1);
  }

  addDishToMenu(dish) {
    menu.push(dish);
  } 

I get the error message:

  ReferenceError: menu is not defined
    at DinnerModel.addDishToMenu (src/model/dinnerModel.js:76:5)
    at Context.<anonymous> (src/model/dinnerModel.test.js:204:15)
1
  • menu !== this.menu Commented Oct 31, 2019 at 15:33

1 Answer 1

7

Simple- you forgot to use this in addDishToMenu:

this would work:

addDishToMenu(dish) {
  this.menu.push(dish);
} 

also, as a side note- instead of using new Array() you can just initialize it to [].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.