Project meal maker

const menu = {
    _courses: {
        appetizers: [],
        mains: [],
        desserts: []
    get appetizers(){
        return this._courses.appetizers;
    get mains(){
        return this._courses.main;
    get desserts(){
        return this._courses.desserts;
    set appetizers(appetizers){
        this._courses.appetizers = appetizers;
    set mains(main){
        this._courses.main = main;
    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._course[courseName].push(dish);
      const dishes = this._course[courseName];
      const randomIndex = Math.floor(Math.random() * dishes.length);
      return dishes[randomIndex];
    generateRandomMeal() {
        const appetizer = this.getRandomDishFromCourse('appetizers');
        const main = this.getRandomDishFromCourse('main');
        const dessert = this.getRandomDishFromCourse('desserts');
        const totalPrice = appetizer.price + main.price + dessert.price;
        return `Your meal is ${}, ${} and ${}. The total price is ${totalPrice}`;

menu.addDishToCourse('appetizers', 'Salad', 4.00);
menu.addDishToCourse('appetizers', 'wings', 4.5);
menu.addDishToCourse('appetizers', 'fries', 5.00);

menu.addDishToCourse('main', 'steak', 7.25);
menu.addDishToCourse('main', 'salmon', 3.25);
menu.addDishToCourse('main', 'tofu', 5.20);

menu.addDishToCourse('desserts', 'ice cream', 3.25);
menu.addDishToCourse('desserts', 'coffe', 3.25);
menu.addDishToCourse('desserts', 'cake', 3.00);

I did it but when I want to run the console return to me:
return this._course[courseName].push(dish);

TypeError: Cannot read property ‘appetizers’ of undefined’
I don’t know what is wrong

addDishToCourse() is a setter method and should not need a return. The action is performed directly upon object.

Remove return and correct the name to courses, and see if that helps.

The task number 8 said ’ The method should then push this dish object into the appropriate array in your menu ‘s _courses object based on what courseName was passed in.’ , so, I removed the return and left


The console returns this ‘TypeError: Cannot read property ‘push’ of undefined’ , I can’t find my error :frowning:

Check the context. The getter is in menu context so the assignments will need to include the backing variable.


This exercise can be done in a variety of ways. Best to strip it down to just enough code to build up the arrays and view their contents. Log the contents of every array.

console.log(    // uses the courses getter