Hi, I’m really struggling to understand how objects work as well as finishing the Meal Maker project.
const menu = {
_courses: {
appetizers: [],
mains: [],
desserts: [],
},
get appetizers() {
return this._courses.appetizers;
},
set appetizers(appetizerIn) {
this._courses.appetizers = appetizerIn;
},
get mains() {
return this._courses.mains;
},
set mains(mainIn) {
this._courses.mains = mainIn;
},
get desserts() {
return this._courses.desserts;
},
set desserts(dessertIn) {
return this._courses.desserts = dessertIn;
},
get courses() {
return _courses;
},
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: courseName,
price: dishPrice,
};
return this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName) {
const dishes = this._courses[courseName];
const index = Math.floor(Math.random() * dishes.length);
return dishes[index];
},
generateRandomMeal() {
const appetizers = this.getRandomDishFromCourse('appetizers');
const mains = this.getRandomDishFromCourse('mains');
const desserts = this.getRandomDishFromCourse('desserts');
const totalPrice = appetizers.price + mains.price + desserts.price;
return `Your three-course meal is ${appetizers.name}, ${mains.name}, and ${desserts.name}. Your total price is ${totalPrice} dollars.`
}
};
menu.addDishToCourse('appetizers', 'Chicken', 10);
menu.addDishToCourse('appetizers', 'Turkey', 12.50);
menu.addDishToCourse('appetizers', 'Salad', 8.50);
menu.addDishToCourse('mains', 'Burger', 15.99);
menu.addDishToCourse('mains', 'Salmon', 20.50);
menu.addDishToCourse('mains', 'Tacos', 11.99);
menu.addDishToCourse('desserts', 'Chocolate', 10);
menu.addDishToCourse('desserts', 'Ice Cream', 10);
menu.addDishToCourse('desserts', 'Hot Fudge', 10);
meal = menu.generateRandomMeal();
console.log(meal);
When I log meal to the console, it gives the right price but always prints appetizers, mains, and desserts instead of the course names. I’m also really struggling to understand how each function other than generateRandomMeal inside the menu object works, even after taking notes from the previous lesson. What have i done wrong, and how is menu supposed to work?