Meal maker

in the code we say that the price is not defined,
here is the code

Let’s trace it back:

This code is where the problem begins, it’s going to throw an error for main and also for dessert.

   const appetizer = this.getRandomDishFromCourse('appetizers');
   const main = this.getRandomDishFromCourse('mains');
   const dessert = this.getRandomDishFromCourse('desserts');

But the question is why? So let’s look at getRandomDishFromCourse()

getRandomDishFromCourse(courseName) {
   const dishes =  this._courses[courseName];
   const  randomIndex = Math.floor(Math.random()* dishes.length);
   return dishes[randomIndex];

The key line in the above for me is dishes[randomIndex]…
This implies that for appetizers, for desserts, for mains, we have something to draw from.
Is it defined? Where do we define it? Where do we instantiate the existence of dishes to draw randomly from?

Which leads to this line:

menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25);

The code only added one dish to the appetizers menu so trying to extract dishes from the other menus is going to return undefined items.

The code should run, it’s just missing a few extra pieces.


thank you. Its works

Why is your get method the same name as your _courses properties when they specifically said in the getter lesson not to do that. However the code still works even though they said it would cause an infinite call back or something.

It works because appetizers, mains and desserts are part of the _courses property. They can’t be named the same if they’re on the top level. So in this scenario, you wouldn’t be able to have a getter/setter named _courses