Meal Maker JS Project

I’ve been looking over this code for a long time trying to figure out why it isn’t working for the Meal Maker Project. I watched the video walkthrough and I just cannot find where I am going wrong, so I thought I’d ask for help. It seems like maybe the scope for the const dish is wrong for what I want to use it for, but that’s how they did it in the video and it works out fine for the expert leading it. I keep getting an error that tells me the following. My code is below the error message. I would greatly appreciate any help you may have. Thank you very much!

/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:37
 return   this._courses[courseName].push(dish);
                                   ^

TypeError: Cannot read property 'push' of undefined
    at Object.addDishToCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:37:36)
    at Object.<anonymous> (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:53: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)

My Code:

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: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 `Your meal will be ${appetizer.name}, ${main.name}, and ${dessert.name}, which will cost a total of ${totalPrice} dollars.`;
   },
};

menu.addDishToCourse('Appetizer', 'Salad', "$6.00");
menu.addDishToCourse('Main Course', 'Chicken Parmesan', "$16.00");
menu.addDishToCourse('Dessert', 'Homemade Pie', "$3.00");


menu.addDishToCourse('Appetizer', 'Guacamole', "$7.00");
menu.addDishToCourse('Main Course', 'Enchiladas', "$10.00");
menu.addDishToCourse('Dessert', 'Cinnamon Ice Cream', "$2.00");


menu.addDishToCourse('Appetizer', 'Bruschetta', "$5.00");
menu.addDishToCourse('Main Course', 'Penne alla Vodka', "$14.00");
menu.addDishToCourse('Dessert', 'Cannolis', "$7.00");

const meal = menu.generateRandomMeal();
console.log(meal);

/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:37
 return   this._courses[courseName].push(dish);
                                   ^

Okay, so you’re getting a TypeError when you attempt to push(dish), this is telling you that this._courses[courseName] is not an array.

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

Using console.log() in addDishToCourse like above will give you some insight into what is happening inside the method.

You were doing so well until you got here.

menu.addDishToCourse('Appetizer', 'Salad', "$6.00");
menu.addDishToCourse('Main Course', 'Chicken Parmesan', "$16.00");
menu.addDishToCourse('Dessert', 'Homemade Pie', "$3.00");

It appears as if you have forgotten all about what you did before. The above mentioned code causes all kinds of issues in the addDishToCourse method and the generateRandomMeal method.

I am getting the same error , gor error with my code then i followed the follow along video still same error…how did you solve it ??

Thanks heaps!!!
i followed your instructions…it took just 2 min to solve my issue( which i was trying to solve for 2day)