Meal Maker HELP

Hi! I’ve been doing the Meal Maker project and I have been stuck trying to find out what my error is.

I’ve been using other website JavaScript apps to see what my error is and they all point to the .push section of code on line 38. The problem is, I am not sure HOW to fix this and have my new inputs be moved into the dish variable.

My code is below:

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  },
  
  get courses() {
    return {
      appetizers: this.appetizers,
      mains: this.mains,
      desserts: this.desserts,
    };
  },
  
  get appetizers() {
    return this._course.appetizers;
  },
  
  set appetizers(appetizerIn) {
    this._course.appetizers = 'appetizer';
  },
  
  get mains() {
    return this._course.mains;
  },
  set mains(mainsIn) {
    this._course.mains = 'main';
  },
  get desserts() {
    return this._course.desserts;
  },
  set desserts(dessertsIn) {
    this._course.desserts = 'dessert';
  },

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

  getRandomDishFromCourse: function() {
    const dishes = this._courses[courseName];
    const randomIndex = Math.floor(Math.random() * dishes.length);
  },

  generateRandomMeal: function() {
    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 is ${appetizer.name}, ${main.name}, ${dessert.name}. The price for your meal tonight is $${totalPrice}`;
  }
};

menu.addDishToCourse('appetizers', 'Miso', 3.50);
menu.addDishToCourse('mains', 'Sushi', 8.50);
menu.addDishToCourse('dessert', 'Tea', 4.00);

Thank you for your help and fresh pair of eyes!

You issue is because this._courses[courseName].push(dish); is failing to find a matching courseName on _courses. Which course name is it failing on? menu.addDishToCourse('dessert', 'Tea', 4.00);

What course names do we have to choose from?

_courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  }

You’re missing a letter.

5 Likes

I find myself making that mistake over and over in my coding. Always just one digit/letter that is missing. Thank you for catching that! :slight_smile:

Thanks for the great reply!
Rarely find people explaining how to troubleshoot.

Hi, There!

Since I set up my VCode with a live server plugin, I have revisited my previous projects on my Full Stack Developer course.
I want to learn how to effectively use VS and the Inspect Element tool to test my previous projects.
When I tested the ‘MEAL MAKER’ project, I got an error that I have no idea how to fix it.
Would somebody be able to help me with this error, please?

Here is 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) {
return this._courses.appetizers = appetizers;
},
set mains(mains) {
return this._courses.mains = mains;
},
set desserts(desserts) {
return this._courses.desserts = desserts;
},

get _courses() {
return {
appetizer: this.appetizers,
mains: this.mains,
desserts: this.desserts
}
},

get courses() {
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts
}
},

addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
name: dishName,
price: dishPrice
}
this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName) {
const dishes = this._courses[courseName];
const randomNumber = Math.floor(Math.random() * dishes.lenght);
return dishes[randomNumber];
},

generateRandomMeal() {
const f = this.getRandomDishFromCourse;
let a, b, c;
[a, b, c] = [f(‘appetizers’), f(‘mains’), f(‘desserts’)];
return Your appetizer is ${a.name}, your main ${b.name}, and your dessert is ${c.name}. Enjoy!
}
};

menu.addDishToCourse(‘appetizers’, ‘Fried Fish’, 4.30)
menu.addDishToCourse(‘appetizers’, ‘Fried Onion’, 5.20)
menu.addDishToCourse(‘appetizers’, ‘Calamary’, 7.50)
menu.addDishToCourse(‘mains’, ‘Pasta’, 12.30)
menu.addDishToCourse(‘mains’, ‘Orange Chiken’, 15.10)
menu.addDishToCourse(‘mains’, ‘Broccoli’, 9.80)
menu.addDishToCourse(‘desserts’, ‘Cookies’, 3.50)
menu.addDishToCourse(‘desserts’, ‘Flan’, 5.70)
menu.addDishToCourse(‘desserts’, ‘Fruit Salad’, 5.90)

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

</>

Debug Error

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 course(){
return {
apepetizers: 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 dish = this._courses[courseName];
const randomIndex = Math.floor(Math.random() * dish.length);
return( dish[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 is ${appetizer.name}, ${main.name} and ${dessert.name} and your total price is ${totalPrice}
}
};

menu.addDishToCourse(‘appetizer’,‘Vegetable Salad’, 11.00);
menu.addDishToCourse(‘appetizer’,'Toasted Bread ', 21.00);
menu.addDishToCourse(‘appetizer’,‘Salad’, 9.40);

menu.addDishToCourse(‘main’,‘Banku’, 21.50);
menu.addDishToCourse(‘main’,'Jollof ', 8.00);
menu.addDishToCourse(‘main’,‘Fufu’, 14.00);

menu.addDishToCourse(‘dessert’,‘Rice Balls’, 51.00);
menu.addDishToCourse(‘dessert’,‘Plain Rice’, 31.00);
menu.addDishToCourse(‘dessert’,‘Yam Stew’, 51.00);

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

Am having error this._courses[courseName].push(dish);
** ^**

TypeError: Cannot read property ‘push’ of undefined
Can someone please help with it thank you

2 Likes

I’m also having this issue, is there a post that solves this?

The most common error seems to be this:

the properties of _courses are spelled appetizers, mains, and desserts at the beginning;

  _courses: {
    appetizers: [],
    mains: [],
    desserts: []
 },

but there’s an error when you use appetizer, main, or dessert at the end:

menu.addDishToCourse('appetizer', 'salad', 9.40);
menu.addDishToCourse('main', 'steak and potatoes', 10);
menu.addDishToCourse('dessert', 'iced cream', 8);

because they’re missing the s, and thus are not recognized as properties of _courses