Meal Maker steps 4-6 not needed

Hi everyone, I am a bit confused a bit by steps 4-6 in this exercise. They are superfluous, because the steps afterwards use push methods to populate the _courses arrays, and object methods are created that retrieve the values from these arrays quite easily.

Here are the superfluous steps:
Step 4: Create getter and setter methods for the appetizers, mains, and desserts properties.
Step 5: Inside your menu object, create an empty getter method for the _courses property
Step 6: Inside the courses getter method, return an object that contains key/value pairs for appetizers, mains, and desserts.

If you delete these parts of the code, the program will run fine. Just go from step 3 to step 7.

So… Why are the steps in there if they are not relevant to the program? Are we meant to experiment with ‘get’ and ‘set’ more in this project?

Thank you !

Course material often presents this way. The more for the practice than the practical uses of concepts. Demonstration is a big part of the early exposure a learner gets.

Just to clarify your points, we could use a link to the exercise/project if you would be so kind as to post it, please.

Thanks mtf, here is a link I think

Meal Maker Project (PRO only)

1 Like
{ appetizers: 
   [ { name: 'wings', price: 6.5 },
     { name: 'chips', price: 3 },
     { name: 'pretzel', price: 5 } ],
   [ { name: 'pizza', price: 12 },
     { name: 'burger', price: 9 },
     { name: 'pasta', price: 12 } ],
   [ { name: 'pie', price: 3 },
     { name: 'cake', price: 3 },
     { name: 'cookie', price: 2.5 } ] }
Your meal is chips, burger, pie. Your total is $15.00.

This line is the kicker…

this._courses[courseName] = dish;

The object on the left has a getter & setter, so the syntax correctly adds the dish to its intended course.

So there is no need for the push method anywhere in this exercise??

I suppose I don’t really understand the purpose of these steps:

I commented out these two blocks of code and the program ran correctly. I assume that’s because the instructions said to use a push method to add dishes to the courses arrays.

… other than their respective setters, not really.

I admit that I did not read the instructions yet, but spotted this in my code and just took it to be of some meaning to the question. However, if the exercise has not progressed to this point (actually using the getters and setters) then I am duly wrong in suggesting that code. However, moving forward it does show the need for all those getters and setters. My apologies if I’m off track.

The purpose of this getter is to return a plain object, so no hocus-pocus. It will be a plain object.

    appetizers: [ .. ],
    mains: [ .. ],
    desserts: [ .. ]

You’ll notice that there is no need to add a new course, since that would involve adding new getters and setters, which is a bit more involved than we ever want to get in this project. That’s why we add new items to courses. Adding a new course really means writing in the software for it.

Setters need Getters

They depend upon them since that is how the syntax is written.

instance.attr = value

The getter is getting the first call. Seeing the assignment it constucts the set call internally and passes the assigned value as the argument.

Note that the actual attribute is not the one we refer to. That attribute has a prefix. _. Yet internally JS is able to route the above statement through the instance method(s) to complete the task.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.