Menu Maker project: Example 'setter' code incorrect?

Menu Maker project

  1. Create getter and setter methods for the appetizers , mains , and desserts properties.

This step gave me pause when I reached the latter half of the project. Inadequate context is provided about the intended use of the setters in this project (and the solution is poorly explained, IMHO).

The experienced developer in the walkthrough video adds code to this sort of effect:

set appetizers(newDish) {

    this._courses.appetizers = newDish


I tested this solution using the following:

menu.appetizers = {dishName: 'Homemade hummus', dishPrice: 6.00}

menu.appetizers = {dishName: 'Chicken soup', dishPrice: 5.50}


The result is:
{ dishName: 'Chicken soup', dishPrice: 5.5 }

  1. Am I right in saying the setter overwrites the existing appetizers?
  2. Why would we want it to do this (versus using the push() method, for e.g.)?
  3. The setters don’t appear to be called in the project. Why are they there; ‘best practice’?
  1. Yes
  2. Well, you don’t want to do this. You may use a setter though in the context of adding all menu items in one go as an array of meals. In the context of this exercise the setters are not being used. Good on you to figure that out ;).
  3. Best Practice, yes.

Happy coding!

1 Like

@janneslohmeijer Thank you for your fast response and peace of mind.

I hit the very next project (Team Stats) this morning and absolutely crushed it out before even reading through all the steps. A little extra clarity in a project brief goes a long way towards understanding what needs to be done and why (good real-world practice for dealing with clients)! :laughing:

1 Like