Meal Maker Getter and Setter errors

Hi. I can’t figure out why this code is giving me errors on the getter methods, I’d really appreciate it if someone could tell me what am doing wrong.
Thanks

const menu = {

_courses: {

 appetizers: [],

 mains: [],

 desserts: []

},

get appetizers(appetizers) {

return this._courses.appetizers;

},

get mains(mains){

return this._courses.mains;

},

get desserts(desserts){

return this._courses.desserts;

},

set appetizers(appetizers){

 this._courses.appetizers = appetizers

},

set mains(mains){

 this._courses.mains = mains

},

set desserts(desserts){

 this._courses.desserts = desserts

},

get courses(){

return {

  appetizers: this.appetizers,

  mains: this.mains,

  desserts: this.desserts,

};

},

addDishToCourse(courseName, dishName, dishPrice){

const dish ={

 name: dishName,

 price: dishPrice,

};

return this._courses(courseName).push(dish;)

},

getRandomDishFromCourses(courseName){

const dishes = this._courses[courseName];

const randomIndex = Math.floor(Math.random() * dishes.length);

return dishes[randomIndex];

},

generateRandomMeal(){

const appetizers = this.getRandomDishFromCourse('appetizers');

const mains= this.getRandomDishFromCourse('mains');

const desserts = this.getRandomDishFromCourse('desserts');

const totalPrice = appetizer.price + main.price + desserts.price;

return `Your meal is ${appetizer.name},${main.name},${desserts.name}, and the total price is ${totalPrice}.`;

}

};

menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25);

menu.addDishToCourse('appetizers', 'Samosa', 2.50);

menu.addDishToCourse('appetizers', 'Mint Peas', 5.25);

menu.addDishToCourse('mains', 'Steak', 12.00);

menu.addDishToCourse('mains', 'Grilled Fish', 1525);

menu.addDishToCourse('mains', 'Chicken', 7.95);

menu.addDishToCourse('desserts', 'Ice Cream', 4.25);

menu.addDishToCourse('desserts', 'Tea', 4.25);

menu.addDishToCourse('desserts', 'Cake', 4.25);

let meal = menu.generateRandomMeal();

console.log(meal);

I get the following error:

Uncaught SyntaxError: getter functions must have no arguments

which is here:

get appetizers(appetizers) 

the getter can’t have appetizers argument/parameter, according to MDN:

The get syntax binds an object property to a function that will be called when that property is looked up.

if the getter has a parameter, JavaScript is not able to create the property from the getter

1 Like