Meal Maker project error when running [SOLVED]

Hi,

Can someone please help with my code below, if I feel like its got loads of errors in it, but I’m currently getting the following error.

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

TypeError: Cannot read property ‘push’ of undefined
** at Object.addDishToCourse (/home/ccuser/workspace/learn**

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: []
  },
    get appetizers() {
      return this._courses.appetizers;
  },
    set appetizers(appetizerIn) {
      this._courses.appetizers = appetizerIn;
  },
    get mains() {
      return this._courses.mains;
  },
    set mains(mainsIn) {
      this._courses.mains = mainsIn;
  },
    get desserts() {
      return this._courses.desserts;
  },
    set desserts(dessertIn) {
      this._courses.appetizers = dessertIn;
  },
  get courses() {
    return {
     appetizers: this.appetizerIn,
     mains: this.mainsIn,
     desserts: this.dessertIn
		}
  },
  addDishToCourse: function (courseName, dishName, dishPrice) {
    const dish = {
      name: dishName,
      price: dishPrice
    }
		this._courses[courseName].push(dish);
  },
  getRandomDishFromCourse: function (courseName) {
    const dishes = this._courses[courseName];
    const randomIndex = Math.floor(Math.random * dishes.length);
    return dishes[randomIndex];
  },
  generateRandomMeal: function () {
    const appetizer = this.getRandomDishFromCourse(this._courses.appetizer);
    const main = this.getRandomDishFromCourse(this._courses.main);
    const dessert = this.getRandomDishFromCourse(this._courses.dessert);
    const totalPrice = courseName[0].price + courseName[1].price + courseName[2].price;
    
    return `Your meal is ${courseName[0].name}, ${courseName[1].name} and ${courseName[2].name} The price is $${totalPrice}.`;
  }
}

menu.addDishToCourse('appetizer', 'soup', 7);
menu.addDishToCourse('appetizer', 'crab', 9);
menu.addDishToCourse('appetizer', 'bruscetta', 4);
menu.addDishToCourse('main', 'lamb shank', 12);
menu.addDishToCourse('main', 'steak and chips', 16);
menu.addDishToCourse('main', 'lamb curry', 13);
menu.addDishToCourse('dessert', 'ice cream', 5);
menu.addDishToCourse('dessert', 'fudge cake', 6);
menu.addDishToCourse('dessert', 'tiramasu', 4);

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

I know that this._courses[courseName].push(dish); is undefined and you cant push to an undefined value, but i have no idea how to solve it, as its the same as the answer provided from code academy, but can’t get it to work.

Thanks for your help,

the problem is that

menu.addDishToCourse('appetizer', 'soup', 7);
menu.addDishToCourse('main', 'lamb curry', 13);
menu.addDishToCourse('dessert', 'ice cream', 5);

should be appetizers whit the s, mains and desserts since your arrays are:

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: []
  }

and in the code when you call the functions like here

this.getRandomDishFromCourse(this._courses.appetizer);

this._courses.appetizers

Also you are not puting ; after the object declaration like
var car = {type:"Fiat", model:"500", color:"white"};

const dish = {
      name: dishName,
      price: dishPrice
    }

Thanks for this, I’ve made the changes and I’m getting an error on the dishes variable saying that its undefined, but again, I don’t get why this._courses[courseName]; would undefined in this instance.

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: []
  },
    get appetizers() {
      return this._courses.appetizers;
  },
    set appetizers(appetizerIn) {
      this._courses.appetizers = appetizerIn;
  },
    get mains() {
      return this._courses.mains;
  },
    set mains(mainsIn) {
      this._courses.mains = mainsIn;
  },
    get desserts() {
      return this._courses.desserts;
  }, 
    set desserts(dessertIn) {
      this._courses.appetizers = dessertIn;
  },
  get courses() {
    return {
     appetizers: this.appetizerIn,
     mains: this.mainsIn,
     desserts: this.dessertIn
		}
  },
  addDishToCourse: function (courseName, dishName, dishPrice) {
    const dish = {
      name: dishName,
      price: dishPrice
    };
		this._courses[courseName].push(dish);
  },
  getRandomDishFromCourse: function (courseName) {
    const dishes = this._courses[courseName];
    const randomIndex = Math.floor(Math.random * dishes.length);
    return dishes[randomIndex];
  },
  generateRandomMeal: function () {
    const appetizer = this.getRandomDishFromCourse(this._courses.appetizers);
    const main = this.getRandomDishFromCourse(this._courses.mains);
    const dessert = this.getRandomDishFromCourse(this._courses.desserts);
    const totalPrice = appetizer.price + main.price + dessert.price;
    
    return `Your meal is ${appetizer.name}, ${main.name} and ${dessert.name} The price is $${totalPrice}.`;
  }
}

menu.addDishToCourse('appetizers', 'soup', 7);
menu.addDishToCourse('appetizers', 'crab', 9);
menu.addDishToCourse('appetizers', 'bruscetta', 4);
menu.addDishToCourse('mains', 'lamb shank', 12);
menu.addDishToCourse('mains', 'steak and chips', 16);
menu.addDishToCourse('mains', 'lamb curry', 13);
menu.addDishToCourse('desserts', 'ice cream', 5);
menu.addDishToCourse('desserts', 'fudge cake', 6);
menu.addDishToCourse('desserts', 'tiramasu', 4);

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

Managed to solve it, answer below for anyone interested.

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: []
  },
    get appetizers() {
      return this._courses.appetizers;
  },
    set appetizers(appetizerIn) {
      this._courses.appetizers = appetizerIn;
  },
    get mains() {
      return this._courses.mains;
  },
    set mains(mainsIn) {
      this._courses.mains = mainsIn;
  },
    get desserts() {
      return this._courses.desserts;
  }, 
    set desserts(dessertIn) {
      this._courses.appetizers = dessertIn;
  },
  get courses() {
    return {
     appetizers: this.appetizerIn,
     mains: this.mainsIn,
     desserts: this.dessertIn
		}
  },
  addDishToCourse: function (courseName, dishName, dishPrice) {
    const dish = {
      name: dishName,
      price: dishPrice
    };

		this._courses[courseName].push(dish);
  },
  getRandomDishFromCourse: function (courseName) {
    const dishes = courseName;
 
    const randomIndex = Math.floor(Math.random() * dishes.length);
    console.log(dishes[randomIndex]);
    return dishes[randomIndex];
    
  },
  generateRandomMeal: function () {
    const appetizer = this.getRandomDishFromCourse(this._courses.appetizers);
    const main = this.getRandomDishFromCourse(this._courses.mains);
    const dessert = this.getRandomDishFromCourse(this._courses.desserts);
    const totalPrice = appetizer.price + main.price + dessert.price;
    
    return `Your meal is ${appetizer.name}, ${main.name} and ${dessert.name} the price is $${totalPrice}.`;
  }
  

}
menu.addDishToCourse('appetizers', 'soup', 4.25);
menu.addDishToCourse('appetizers', 'crab', 8.95);
menu.addDishToCourse('appetizers', 'bruscetta', 4.75);
menu.addDishToCourse('appetizers', 'mushrooms', 3.75);
menu.addDishToCourse('appetizers', 'cheese spead', 11.75);
menu.addDishToCourse('mains', 'lamb shank', 12.75);
menu.addDishToCourse('mains', 'steak and chips', 16.75);
menu.addDishToCourse('mains', 'lamb curry', 13.25);
menu.addDishToCourse('mains', 'Fish stew', 16.50);
menu.addDishToCourse('mains', 'cottage pie', 13);
menu.addDishToCourse('mains', 'lobstar', 22.50);
menu.addDishToCourse('desserts', 'ice cream', 5);
menu.addDishToCourse('desserts', 'fudge cake', 5.75);
menu.addDishToCourse('desserts', 'coffee', 2.75);
menu.addDishToCourse('desserts', 'cheesecake', 5.50);
menu.addDishToCourse('desserts', 'bread and butter pudding', 5.25);
menu.addDishToCourse('desserts', 'apple stroodle', 4.25);


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