Meal Maker Project Error

So, I’m at my wit’s end with this project. I can’t for the life of me figure out where this error is coming from. I’m working on the JavaScript Meal Maker Project =>

this is my code:

const menu = {
  _courses : {
    appetizers: [],
    mains: [],
    desserts: [],
  get appetizers() {
    return this._courses.appetizers;
  set appetizers(app) {
  get mains() {
    return this._courses.mains;

  set mains(main) {
  get desserts() {
    return this._courses.desserts;

  set desserts(dessert) {
  get courses(){
    return {
      appetizers : this.appetizers,
      mains : this.mains,
      desserts : this.desserts
  addDishToCourse(courseName, dishName, dishPrice) {
    return dish = {
      name: dishName,
      price: dishPrice
  getRandomDishFromCourse(courseName) {
    const dishes = this._courses[courseName];
    const randIndex = Math.floor(Math.random()*dishes.length)
    return dishes[randIndex];
  generateRandomMeal() {
    let appetizer = this.getRandomDishFromCourse('appetizers');
    let main = this.getRandomDishFromCourse('mains');
    let dessert = this.getRandomDishFromCourse('desserts');
    const totalPrice = appetizer.price + main.price + dessert.price;
    return `your meal is ${}, ${}, and ${}. The price is $$

menu.addDishToCourse('appetizers', 'salad', 4.00 )
menu.addDishToCourse('appetizers', 'soup', 6.00 )
menu.addDishToCourse('appetizers', 'mozzerella sticks', 5.00 )

menu.addDishToCourse('mains', 'Hamburger', 10.00 )
menu.addDishToCourse('mains', 'Rib eye', 21.00 )
menu.addDishToCourse('mains', 'Chicken Cordon Bleu', 16.00 )

menu.addDishToCourse('desserts', 'ice cream', 3.00 )
menu.addDishToCourse('desserts', 'canoli', 4.50 )
menu.addDishToCourse('desserts', 'tiramasu', 7.75 )

meal = menu.generateRandomMeal();

and I receive the following 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:51:33)
    at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:70:13)
    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)

Does anyone have a guess as to what I’m missing??

Your program never reaches this line of code: this._courses[courseName].push(dish); inside of your addDishToCourse method.

1 Like

I’m not sure why that would be. Do I have a syntax error or something else simple that I missed.

Well look at what you wrote right above it. What does the return keyword do?

1 Like

It creates the dish object. I’m not sure how that would prevent this._courses[courseName].push(dish); from running.

Oh MY Gosh… I’m a freaking moron :rofl: :joy: :rofl:
Thanks for the help!!

Don’t worry, its going to happen a lot. You just have to get experienced at debugging. I still make simple spelling and syntax errors after years that I spend hours debugging.

1 Like