Meal Maker Project HELP

Hello! I need some help with the Meal Maker Project, for some reason my meals aren’t posting to the console correctly. Instead of producing a randomized meal, I get this: Your meal is appetizers, mains, desserts The price is 21. Can someone please take a look at my code thus far and help me fix it. Thank you!

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: courseName, 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 appetizers = this.getRandomDishFromCourse('appetizers'); const mains = this.getRandomDishFromCourse('mains'); const desserts = this.getRandomDishFromCourse('desserts') const totalPrice = appetizers.price + mains.price + desserts.price; return `Your meal is ${appetizers.name}, ${mains.name}, ${desserts.name} The price is ${totalPrice}.`; }, }; menu.addDishToCourse('appetizers', 'Tater Tots', 3.00); menu.addDishToCourse('appetizers', 'water', 1.00); menu.addDishToCourse('appetizers', 'salad', 4.00); menu.addDishToCourse('mains', 'steak', 15.00); menu.addDishToCourse('mains', 'burger', 12.00); menu.addDishToCourse('mains', 'soup', 10.10); menu.addDishToCourse('desserts', 'ice cream', 5.00); menu.addDishToCourse('desserts', 'pie', 6.00); menu.addDishToCourse('desserts', 'cake', 7.00); let meal = menu.generateRandomMeal(); console.log(meal);

Hi,
have a look at the addDishToCourse method in the codebyte. One parameter is greyed out. That means that you don’t use it.
Therefore you’re using courseName twice:

const dish = {
        name: courseName,
        price: dishPrice,
      };
return this._courses[courseName].push(dish);

You don’t need to return from that method. Pushing to the _courses object is all that method is supposed to do. But that doesn’t cause the error.

Thank you so much! It’s working perfectly now.

1 Like