Meal Maker Project - Why do we need setters and getters?

Hi all, sorry if my question looks weird :slight_smile:

I’m working on the Meal Maker Project, and I was just wondering - why do we need to use the setters and getters (as described in points 4,5, 6) in the first place? Even if I remove them and only do the rest parts of the tasks, the code seems to work in the same way, returning the result perfectly well.

Can someone explain to me, why and if we really need using getters and setters here, or was it included mostly for us to train our skills?

Thanks in advance!

Train your skills. Get the exercise to pass by the examples and instructions given, then challenge yourself to get it to work with the getters and setters. It is a challenge, to be sure but not an insurmountable one. You just need to keep a close eye on context.

Hey mtf, first of all, thanks for all the time and attention you give these forums.

Secondly, could you please explain how the task wants me to use the setters?
I feel like I understand what getters and setter can do, but I’ve been staring at this code for some time and I don’t know how I get 2 values (name & price) into the setter method when ‘set’ only accepts one parameter.

Thank you.

Hey Robert,

Since you’re creating the dish object in the addDishToCourse() method, you can pass that object to your setter method as one argument & then push the entire object to whichever courseName array you’re adding to.

I found that if I changed this one line of code:
return this._courses[courseName].push(dish);
The program worked with this change but I’m unclear if get courses() was called or a setter was called or both. I found it difficult to step through the getter/setter part of the object.

Also when I changed these lines of code in the menu object:
// Step 4 create setter methods
set appetizers(dataIn) { = dataIn;
}, // end set appetizers
set mains(dataIn) { = dataIn;
}, // end set mains
set desserts(data) { = dataIn;
}, // end set desserts
the program continued to work; hence, the must call the get appetizers getter method. When I comment out get appetizers the program no longer works!