Hello everyone,
I’m currently working on the Random Meal Generator code from the Full Stack Developer Course. In the project walkthrough we’re advised to create setter and getter methods for every one of the dishes. Nevertheless, the code works just fine without them as well. I think they could have a useful functionality, but I fail to understand which one. Could someone explain why we would need setter- and getter-methods in that code?
My code here, I have the getter and setter methods but as a comment and the code works just fine 
Many thanks in advance!!!
const menu = {
_courses:{
appetizers: [],
mains: [],
desserts: []},
/*
get appetizers(){},
set appetizers(appetizerIn){},
get mains(){},
set mains (mainsIn){},
get desserts (){},
set desserts (dessertsIn){},
*/
get courses(){
return {
appetizers:this.appetizers,
mains: this.mains,
desserts: this.desserts,
}
},
addDishToCourse(courseName,dishName,dishPrice){ const dish ={
name: dishName,
price: dishPrice
};
this._courses[courseName].push(dish)
},
getRandomDishFromCourse(courseName){
const dishes = this._courses[courseName];
const randomIndex = Math.floor(Math.random() * dishes.length);
return dishes[randomIndex]
},
generateRandomMeal(){
const appetizer = this.getRandomDishFromCourse('appetizers');
const main = this.getRandomDishFromCourse('mains');
const dessert = this.getRandomDishFromCourse('desserts');
const totalPrice = appetizer.price + main.price + dessert.price;
return `Your meal is ${appetizer.name}, ${main.name}, ${dessert.name}. The total price is $${totalPrice}.`
}
}
menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25);
menu.addDishToCourse('appetizers', 'Feldsalat and Stuff', 3.00);
menu.addDishToCourse('appetizers', 'Crack sandwich', 0.35);
menu.addDishToCourse('mains', 'Mushroom Wellington', 6.50);
menu.addDishToCourse('mains', 'Pizza', 11.30);
menu.addDishToCourse('mains', 'Lasagna', 5.60);
menu.addDishToCourse('desserts', 'Berry Crumble', 3.50);
menu.addDishToCourse('desserts', 'Brownies', 1.50);
menu.addDishToCourse('desserts', 'Space Cookies', 4.20);
const meal = menu.generateRandomMeal()
console.log(meal)