Meal Maker


#1

Hey everyone I am currently working on the Meal Maker project and I’m having a bit of trouble.
I keep getting this error = "MealMaker.js:42
this._courses[courseName].push(dish);
^

TypeError: Cannot read property ‘push’ of undefined"

Here is the project link.
https://www.codecademy.com/courses/introduction-to-javascript/projects/meal-maker

Here is my currents code, any help is appreciated, thanks!

const menu = {
_courses: {
appetizers:[],
mains:[],
desserts:[],

  set appetizers(appetizerIn) {
    this._appetizers = appetizerIn;
    },
  get appetizers(){
    return this._appetizers;
    },

    set mains(mainIn) {
        this._mains = mainIn;
        },
    get mains(){
        return this._mains;
    },

    set desserts(dessertsIn) {
        this._desserts = dessertsIn;
        },
    get desserts(){
        return this._desserts;
    },
get courses() {
    return {
        appetizers: this._courses._appetizers,
        mains: this._courses._mains,
        desserts: this._courses._desserts
        }
    }
},

addDishToCourse(courseName,dishName,dishPrice){
    const dish = {
        price:dishPrice,
        name: dishName,
    };

    this._courses[courseName].push(dish);
},

getRandomDishFromCourse: function(){    
    const dishes = this._courses[courseName];
    const randomIndex = Math.floor(Math.random() * dishes.length);
    return dishes[randomIndex];
},

generateRandomMeal : function() {
    let appetizer = this.getRandomDishFromCourse('appetizers');
    let mains = this.getRandomDishFromCourse('mains');
    let desserts = this.getRandomDishFromCourse('desserts');
    let totalPrice = appetizers.price + mains.price + desserts.price;

    return `Your meal is ${appetizers.name}, ${mains.name},${desserts.name}, the price is $${totalPrice}.`;
},

};

menu.addDishToCourse(‘appetizers’, ‘Calamari’, 4.25);
menu.addDishToCourse(‘appetizers’, ‘Mozzarella Sticks’, 4.25);
menu.addDishToCourse(‘appetizers’, ‘Salad’, 4.25);

let meal = menu.generateRandomMeal();

console.log(meal());


#2

Some missing prefixes here, according to the rest of your code.


#3

Thank you for your reply, I fixed the prefixes, but I came across another error, I came to find out I didn’t put in enough meal entries. Thank you!