Meal Maker project

Hi everyone,

I’m struggling with finishing the Meal Maker project. Here is my code:

Why the console doesn’t recognize my variable appetizer ? :no_mouth:

Thanks for your (very needed) help !!

Hello, @filou_vico, and welcome to the forums.

When sharing code in a post, screenshots are not the best method. I can’t copy the code, and run it in my own environment to see what the issues may be. Also, the error message you shared is incomplete. Occasionally, a screenshot is helpful to show odd behavior by the the website itself, but not to share code. Please edit your post by pasting your code following the guidelines found here.

1 Like

I spotted the error, but yes what @midlindner says please post your code in a post using code formatting options.

I will however not present the error to you on a silver platter :wink: . Sorry.

You only posted a snippet of the error message, have you read the rest?

    const totalPrice = appetizer.price + main.price + dessert.price;

TypeError: Cannot read property 'price' of undefined

Perhaps you can apply some console.logs to find out what exactly is going on.

Happy coding!

Oh yes I’m sorry, here is my code following the forum guidelines:

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  get appetizers() {
    return this._courses.appetizers;
  get mains() {
    return this._courses.mains;
  get desserts() {
    return this._courses.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 `${} + ${} + ${} = ${price}€`;

menu.addDishToCourse("appetizers", "burratta", 10);
menu.addDishToCourse("appetizers", "mozza", 8);
menu.addDishToCourse("appetizers", "bruscetta", 12);
menu.addDishToCourse("mains", "poulpo", 18);
menu.addDishToCourse("mains", "pizza", 16);
menu.addDishToCourse("mains", "pasta", 14);
menu.addDishToCourse("desserts", "tiramisu", 5);
menu.addDishToCourse("desserts", "choco", 6);
menu.addDishToCourse("desserts", "baba", 7);

const meal = menu.generateRandomMeal();

And here is the error message:

    const totalPrice = appetizer.price + main.price + dessert.price;

TypeError: Cannot read property 'price' of undefined
    at Object.generateRandomMeal (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:43:33)
    at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:58:19)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)

Thanks a lot for your support, I appreciate as a beginner :wink:

1 Like

OK thanks I’ll look again today with console.log()

1 Like

You may have to apply a couple :wink: . Find out where things stop returning an undefined and then see how that last undefined is caused.

OK after a good night of rest I’ve spotted the error :

return this._courses[courseName].push[dish];
should be
return this._courses[courseName].push(dish);

Thansk for the support guys !
Have a good day :slight_smile: