Codecademy meal-maker project

Hello! Here is my completed project for the meal-maker task in the objects pack, this was the most confusing and difficult project I had, I kept having syntax erros and countless attempts to debug it, i finally completed it and have it run smoothly, please take a look and let me know what you think. Also, is there anywhere else I can practice projects like these? Thanks.

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 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(){
    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 is $${totalPrice}.`;
  }
};

menu.addDishToCourse('appetizers', 'Mozzarella sticks', 5.65);
menu.addDishToCourse('appetizers', 'Chips and Salsa', 4.00);
menu.addDishToCourse('appetizers', 'wings', 8.50);
menu.addDishToCourse('mains','Steak', 20.13);
menu.addDishToCourse('mains','Quesadilla', 12.90);
menu.addDishToCourse('mains','Cheeseburger', 10.90);
menu.addDishToCourse('desserts','cake',6.20);
menu.addDishToCourse('desserts','brownies',6.50);
menu.addDishToCourse('desserts','ice cream',6.90);

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







Giving feedback for the first time? AWESOME! Check out this video for a boost of confidence: How to Review Someone Else’s Code
Feel free to remove this message before posting.

Cheers!
—Codecademy Community Managers

1 Like

Here’s mine. Can you tell me what’s wrong with it? Thanks.

Hi @gguirao13
_courses is supposed to be an object. Check the correct syntax of objects and compare it to your _courses object.

Sorry, but I’m still not seeing it. I have a very difficult time seeing minor details because I’m very nearsighted… Are you referring to the second line?

You’re using parenthesis instead of braces for the object.

Which lines? Do you mean 2 and 6? Those are curly bracers.

These are parenthesis…

Can anyone tell me what’s wrong with mine? I’ve spent ages trying to debug although it keeps giving me an error with my .push method
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 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(){

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 is $${totalPrice}.`;

}

};

menu.addDishToCourse(‘appertizers’, ‘Ceasar Salad’, 4.25);

menu.addDishToCourse(‘appertizers’, ‘Garlic Bread’, 4);

menu.addDishToCourse(‘appertizers’, ‘Olives’, 6)

menu.addDishToCourse(‘mains’, ‘steak’, 40);

menu.addDishToCourse(‘mains’, ‘Chicken and Bacon Fetticini’, 28);

menu.addDishToCourse(‘mains’, ‘Spagghetti Bolognese’, 32);

menu.addDishToCourse(‘desserts’, ‘Ice Cream’, 10);

menu.addDishToCourse(‘desserts’, ‘Affogato’, 4);

menu.addDishToCourse(‘desserts’, ‘Cheesecake’, 13);

let meal = menu.generateRandomMeal();

console.log(meal)

Hi @ruby2350228250
Welcome to the forum!
You have better chances of getting help if you post your question in the Get Help category and format your post according to this guideline.
There are already several posts with the same problem. If you don’t have other issues, too, the error message you get is
'TypeError: Cannot read property ‘push’ of undefined at Object.addDishToCourse'
right?
Check if the argument the parameter courseName receives in the method addDishToCourse is the same as the keys in your _courses object.