Meal Maker - return this._courses[courseName].push(dish);


In Meal Maker project I don’t understand addDishToCourse() method, especially part return this._courses[courseName].push(dish);

_Courses object doesn’t have ‘name’ key (it has appetizers, mains, desserts) so what exactly “this._courses[courseName]” does?

Thanks a lot!

Well it pushes dish to a key of _courses.

this._courses[courseName] is the location to push to.

The assignments says to build the method addDishToCourse that takes the following input parameters: courseName, dishName and dishPrice

addDishToCourse (courseName, dishName, dishPrice)

Say we want to add Tomato soup to the ‘appetizers’ in the menu with a price of $5.
‘appetizers’ is the courseName, Tomato soup is the dishPrice and 5 is the price.

The dish is defined by the name and price aka

let dish = {
      name: 'Tomato soup',
      price: 5

Now to your question:


Will do the following:

this._courses[ 'appetizers' ].push( { name: 'Tomato soup', price: 5 } )

Does this answer your questions?

Happy coding!

Thanks a lot, you really helped!

1 Like

I’m so glad I found this. I have really struggled understanding this exact part too. Thanks for that.

1 Like