jS meal maker project (2)

const menu = {
_courses: {
appetizers: ,
mains: ,
desserts: ,
},
get appetizers() {
return this._courses.appetizers;
},
get mains() {
return this._courses.mains;
},
get 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);
},
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}, and ${dessert.name}. Your total is ${totalPrice}.;
}
};
menu.addDishToCourse(‘appetizer’, ‘House Salad’, 4.5);
menu.addDishToCourse(‘appetizer’, ‘Mozz Sticks’, 6.5);
menu.addDishToCourse(‘appetizer’, ‘Lettuce Cups’, 8.5);
menu.addDishToCourse(‘main’, ‘Ribeye’, 14.5);
menu.addDishToCourse(‘main’, ‘Pasta’, 12.5);
menu.addDishToCourse(‘main’, ‘Entree Salad’, 10.5);

menu.addDishToCourse(‘dessert’, ‘Chocolate Mousse’, 7.5);
menu.addDishToCourse(‘dessert’, ‘Cheesecake’, 8.5);
menu.addDishToCourse(‘dessert’, ‘Fruit Tart’, 9.5);

const meal = menu.generateRandomMeal();
console.log(meal);

Please run this and explain what I’m missing. I am getting a TypeError (.push undefined) kicked back. please note I know what the error is and I do not need an explanation of what the error is. I can’t seem to figure out WHY I’m getting this error back. I need to address the WHY of the error.
any help is greatly appreciated

Looking at your definition of _courses:

_courses: {
appetizers: ,
mains: ,
desserts: ,
}

and at how you are adding dishes:

menu.addDishToCourse(‘main’, ‘Ribeye’, 14.5);
menu.addDishToCourse(‘main’, ‘Pasta’, 12.5);
menu.addDishToCourse(‘main’, ‘Entree Salad’, 10.5);

I believe you have a typo on the type of dish you are adding ( you are missing an s).
Your code fails to push a new dish into something that doesn’t exist.

1 Like

this is an earlier version of the code i typed. In the most recent version, i was missing a single ‘s’.
a SINGLE ‘s’ had me on this same piece of code for 2 days.
a thousand thank you’s, also facepalm

1 Like