Hi! This is the ‘Meal Maker’ project. I’m not sure what is causing the error. Anything helps, thanks!!
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(appetizerIn) {
return this._courses.appetizers = appetizerIn;
},
set mains(mainIn) {
return this._courses.mains = mainIn;
},
set desserts(dessertIn) {
return this._courses.desserts = dessertIn;
},
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 `With the ${appetizer.name}, the ${main.name}, and the ${dessert.name} the total price is ${totalPrice}. `;
}
};
menu.addDishToCourse('appetizers', '1', 10);
menu.addDishToCourse('appetizers', '2', 9);
menu.addDishToCourse('appetizers', '3', 8);
menu.addDishToCourse('mains', '4', 10);
menu.addDishToCourse('mains', '5', 10);
menu.addDishToCourse('mains', '6', 10);
menu.addDishToCourse('desserts', '7', 10);
menu.addDishToCourse('desserts', '8', 10);
menu.addDishToCourse('desserts', '9', 10);
const meal = menu.generateRandomMeal();
console.log(meal);
been looking this over. can’t seem to find the what is wrong…
keep getting: 'TypeError: Cannot read property ‘price’ of undefined
at Object.generateRandomMeal ’
p.s. was just to lazy to put in dish names