Meal maker only makes me crazy

Hi, i’m doing the meal maker tutorial and get this error message:

return this._courses[courseName].push(dish);
^ (the arrow is under the dot in push.
TypeError: Cannot read property ‘push’ of undefined

Anyone that can give me som thoughts about the code and what i’m doing wrong.
Thanks in advance!

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._course.appetizers = appetizers; 
  set mains(mains) {
    this._course.mains = mains; 
  set desserts(desserts) {
    this._course.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: function() {
    const appetizer = this.getRandomDishFromCourse('appetizers');
    const mains = this.getRandomDishFromCourse('mains');
    const desserts = this.getRandomDishFromCourse('desserts');
    const totalPrice = appetizers.price + mains.price + desserts.price;
    return `Your meal is ${}, ${} and ${} and the total price is ${totalPrice}`;

menu.addDishToCourse('appetizers', 'Sallad', 4.00);
menu.addDishToCourse('appetizers', 'Soup', 5.00);
menu.addDishToCourse('appetizers', 'Bread', 5.00);
menu.addDishToCourse('mains', 'Pizza', 8.00);
menu.addDishToCourse('mains', 'Steak', 12.00);
menu.addDishToCourse('mains', 'Fish', 11.00);
menu.addDishToCourse('dessers', 'Pannacotta', 7.00);
menu.addDishToCourse('desserts', 'Ice cream', 3.00);
menu.addDishToCourse('desserts', 'Coffe', 2.00);

const meal = menu.generateRandomMeal();

Looks like a simple spelling error. Just a side note: you don’t need to return in this line:
return this._courses[courseName].push(dish);. You are just pushing the object to the proper course array. There is nothing to return to the line of code that called the function.
You’ll also need to fix this:

Thank you very much for the help. I searched for typos but did not think it was in that part of code, would have taken me ages to figure out. Now i can continue with the rest of the errors.

1 Like

Your code worked fine for me after fixing those 2 spelling errors.

Changed the wront code on first try but got it now. Thanks!

1 Like