This is redo 8 and it was from the walk through video and I still get the same errors.
return this._courses[courseName].push(dish);
keeps giving me a typeof error.
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: [],
},
get appetizers() {
return this._courses.appetizers;
},
get mains() {
return this._courses.mains;
},
get desserts() {
return this._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}, and the total price is $${totalPrice}.`;
}
};
menu.addDishToCourse('appetizer', 'Caesar Salad', 4.25);
menu.addDishToCourse('appetizer', 'wings', 5.25);
menu.addDishToCourse('appetizer', 'fries', 1.25);
menu.addDishToCourse('mains', 'chicken', 7.25);menu.addDishToCourse('mains', 'beef', 8.25);menu.addDishToCourse('mains', 'soup', 6.25);
menu.addDishToCourse('desserts', 'ice cream', 3.25);menu.addDishToCourse('desserts', 'cake', 3.75);menu.addDishToCourse('desserts', 'cookies', 1.25);
const meal = menu.generateRandomMeal();
console.log(meal);