Meal Maker

Hi,

I dont know what exactly I’m doing wrong, but running it like this:

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  },    
    get appetizers() {
      return this._courses.appetizers;
    },
    set appetizers(appetizers) {
      return this._courses.appetizers = appetizers;
    },
    get mains() {
      return this._courses.mains;
    },
    set mains(mains) {
      return this._courses.mains = mains;
    },
    get desserts() {
      return this._courses.desserts;
    },
    set desserts(desserts) {
      return 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._cousrses[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 = appetizer.price + main.price + dessert.price;
  return `Your meal is ${appetizer.name}, ${main.name}, ${dessert.name} and the total is ${totalPrice}`
  },
};

menu.addDishToCourse('appetizers', '■■■', 1);

gives me following syntax error:

/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:38
return this._cousrses[courseName].push(dish);
^
TypeError: Cannot read property ‘appetizers’ of undefined
at Object.addDishToCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:38:25)
at Object. (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:54:6)
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)

I looked at the video provided by codecadamy but it is literally basically the same code so idk
I’d really be so happy about some help

1 Like

Hello, @m00nl1t, and welcome to the forums.

Look closely at the error message.

If I asked you to find the menu._cousrses object in your code, could you find it? The computer is telling you that it can’t.

1 Like

I hate myself, it’s always a TYPOOO :sob::sob::sob::sob:
Thank you so much omg

1 Like

Us humans are always going to make mistakes. It’s our nature. The key is to learn to read and follow the error messages, and use a systematic approach to debug our code rather than spending fruitless time proof reading.

1 Like

That’s a great advice thank you so much I’ll write it down and put it next to my screen to remember <3

1 Like