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.
https://www.codecademy.com/courses/introduction-to-javascript/projects/meal-maker
I am getting the following error:
/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:19
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: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};
this._courses[courseName].push(dish);
console.log(${courseName} added: ${dish.name}, ${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 ${appetizer.name}, ${main.name}, and ${dessert.name}. The price is $${totalPrice}.`;
}
};
menu.addDishToCourse(‘appetizers’,‘nachos’,4);
menu.addDishToCourse(‘appetizers’,‘onion rings’,4);
menu.addDishToCourse(‘mains’,‘veggie burger’,5);
menu.addDishToCourse(‘mains’,‘lasagna’,5);
menu.addDishToCourse(‘desserts’,‘cheesecake’,5);
menu.addDishToCourse(‘desserts’,‘pie’,5);
let meal = menu.generateRandomMeal();
console.log('Your meal is: ’ + meal);
Thanks in advance for any guidance.