My 'Meal Maker' code not working. spent hours figuring out why but still don't get it

https://www.codecademy.com/courses/introduction-to-javascript/projects/meal-maker

I’m new to Codecademy. This is my first post so please be patient with me.

First of, I haven’t had issues up until I got to Objects and especially this exercise ‘Meal Maker’. I hate to say this but I completely don’t understand how to put this together. I tried to follow the steps again and again but my code is not working. I watched the video and the guy is going too fast and didn’t help.

Here is what I need help with:

  1. Pleas tell me why my code is not working. I posted the link to it. Please tell me if there is a better way to post codes in the future.
  2. Why do we need setters and getters here
  3. anything that explains this code will help.

Thanks in advance

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  },


  get appetizers() {
    return this._courses.appetizers;
  },
  set appetizers(appetizerIn) {
    this._courses.appetizers;
  },
  get mains() {
    return this._courses.mains;
  },
  set mains(mainIn) {
    this._courses.mains;
  },
  get desserts() {
    return this._courses.desserts;
  },
  set desserts(dessertsIn) {
    this._courses.desserts;
  },


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


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


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


  generateRandomMeal: function() {
    const appetizer= this.getRandomDishFromCourse('appetizers');
    const mains = this.getRandomDishFromCourse('mains');
    const desserts = this.getRandomDishFromCourse('desserts');
    const totalPrice = appetizer.price + mains.price + desserts.price;

    return `Your meal is ${appetizer.name}, ${mains.name}, ${desserts.name}, the price is ${totalPrice}.`
  }
};




menu.addDishToCourse('appetizers', 'Caesar Salad', 4.25);


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






We need to see your code. Please post in a reply using Markdown, not Codebyte.

Asked and answered many times in this topic category. A quick perusal of the existing topics will quickly supply your needs.

The why is less important to understand right now than the how. Let’s get the mechanics down and then the why question is easier to answer with viable examples. For the present, just master the syntax and usage. Nothing changes, we still need to access properties.

1 Like

Your setters need work:

  set appetizers(appetizerIn) {
    this._courses.appetizers;
  },

You didn’t do anything with the argument appetizerIn in that function.
The other set methods have same problem.

The getRandomDishFromCourse function is missing a return.

And,

You’ll need more than just one appetizer to have a full meal here;
a main, and a dessert is needed too.

1 Like

As it stands they are not implemented since the add dish to course method pushes the new entry directly onto the respective array. They would need to work if that method was calling them, but given the current model could even be removed with no effect.

1 Like

Hello everyone,

this project seems to be a nail biting one for most, I have spent days on understanding this project and here is a link to mine with a bit a comments to clarify :slight_smile:
https://github.com/MCheroajdN/Meal-Maker

I hope this help anyone to understand better, and pls any comments helps.

Lets keep coding!