Need Help with Introduction to Javascript Meal Maker Project

Hello all,

I have been stuck on this project for quite some time now, and would love some help.

I had been doing pretty well with the course up until now, but this project seems extra challenging for some reason.

I am getting the following error:


TypeError: Cannot read property ‘push’ of undefined
at Object.addDishToCourse (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:19:26)
at Object. (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:42: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

And here is my code. I’ve tried to incorporate suggestions from other forum posts:

const menu = {
_courses:{appetizers: ,mains: ,desserts: ,set appetizers(appetizer){this._appetizers.push(appetizer);},
set mains(main){this._mains.push(main);},
set desserts(dessert){this._desserts.push(dessert);},
get desserts(){return this._desserts;},
get mains(){return this._mains;},
get appetizers(){return this._appetizers;},
get courses(){
return {appetizers: this._courses.appetizers,mains:this._courses.mains, desserts: this._courses.desserts};


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

console.log(${courseName} added: ${}, ${dish.price});

getRandomDishFromCourse: function(coursename){
const dishes=this._courses[coursename];
const myIndex=Math.floor(Math.random() * dishes.length);
console.log('dishes is ’ + dishes[myIndex]);
return dishes[myIndex];

generateRandomMeal: function (){
const appetizer=this.getRandomDishFromCourse(‘appetizers’);
console.log('appetizers are ’ + this.appetizer);
const main = this.getRandomDishFromCourse(‘mains’);
const dessert = this.getRandomDishFromCourse(‘desserts’);

const totalPrice=appetizer.price + main.price + dessert.price;
return `Your meal is ${}, ${}, and ${}.   The price is $${totalPrice}.`;


menu.addDishToCourse(‘appetizers’,‘onion rings’,4);
menu.addDishToCourse(‘mains’,‘veggie burger’,5);

let meal = menu.generateRandomMeal();
console.log('Your meal is: ’ + meal);

Thanks in advance for any guidance.

1 Like

This error indicates that the object the method is being called on does not exist, or is of the wrong datatype (should be an Array).

If we trace back through your code where the _courses object is defined we see getters and setters but the defined properties are not backing variables (_x). That may be where the problem is.

1 Like

Look at what you called push on
Either there should be something there, and that means you failed to set it, or it shouldn’t be there, and you’re looking in the wrong place.

1 Like

Thanks @mtf, I appreciate you taking the time to reply. I will take a look there.

1 Like

Thanks for taking the time to reply @ionatan.

There are so many new concepts to unpack in this one project, I’ve been struggling.

I’ll keep plugging at it.