Meal maker problem


#1

hey i went over my code again and again and i cant seem to find whats wrong. can anyone help me?

//the code:

const menu = {
_courses: {
_appetizers: [],
_mains: [],
_desserts: [],

get appetizers() {
  return this._appetizers;
},
set appetizers(appetizerIn) {
this._appetizers.push(appetizer);

},
get mains() {
return this._mains;
},
set mains(mainIn) {
this._mains.push(main);
},
get desserets() {
return this._desserts;
},
set desserts(dessertIn) {
this._desserts.push(dessert);
}
},
get courses() {
return {
appetizers:
this._courses.appetizers,
mains:
this._courses.mains,
desserts:
this._courses.desserts
}
},
addDishToCourse(courseName, dishName, dishPrice) {
const dish = {
_name: dishName,
_price: dishPrice
};
this._courses[courseName].push(dish);
},
getRandomDishFromCourse(courseName) {
const dishes = this._courses[courseName];
const randomIndex = Math.floor(Math.random() * dishes.length);
},

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 appetizer was ${appetizer}, your main dish was ${main} and your dessert was ${dessert}, your check will be ${totalPrice.toFixed(2)}`;
}

};

menu.addDishToCourse(‘appetizers’, ‘Caesar Salad’, 4.25);
menu.addDishToCourse(‘appetizers’, ‘green Salad’, 7.98);
menu.addDishToCourse(‘mains’, ‘pizza’, 5);
menu.addDishToCourse(‘mains’, ‘pasta’, 8);
menu.addDishToCourse(‘desserts’, ‘ice cream’, 4.25);
menu.addDishToCourse(‘desserts’, ‘cake’, 500);

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

//the error:

/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:42
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:42:32)
at Object. (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:65: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 (bootstrap_node.js:151:9)


#2

Please remember to include a link to the lesson when posting in Q&A. Also, if you can still edit, remove the foul language from your code.


#3

oh no!
i forgot about it, ill edit it out, thanks :slight_smile:


#4

There are a couple of segments that should be methods, perhaps?

getRandomDishFromCourse: function (...) {

}

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.