MealMakerProject

some of the projects are getting so confusing. The lectures are not that confusing, but projects are, and they are a little bit more advance than the lectures. Is there any solution for it? I practiced the lectures many times, but still get confused in projects. Thank you

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._course.mains = this.mains;

  },



  set desserts(desserts) {

    this._course.desserts = this.desserts;

  },

 get courses() {

    return {

        appetizers: this.appetizers,

      mains: this.mains,

      desserts: this.desserts,

    };

  },

  // I am confused bellow this line. Going through every sections in object, but still I can figoure this out. I did follow the walk though solution and then get everything right. 

  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}, and ${dessert.name}, and the total price is ${totalPrice}`;

}  

};

menu.addDishToCourse(“appetizers”, “salad”, 4.0);

menu.addDishToCourse(“appetizers”, “wings”, 4.5);

menu.addDishToCourse(“appetizers”, “fries”, 5.0);

menu.addDishToCourse(“mains”, “steak”, 10.25);

menu.addDishToCourse(“mains”, “salmon”, 7.75);

menu.addDishToCourse(“mains”, “tofu”, 11.2);

menu.addDishToCourse(“desserts”, “ice cream”, 3.0);

menu.addDishToCourse(“desserts”, “coffee”, 3.0);

menu.addDishToCourse(“desserts”, “cake”, 3.25);

const meal = menu.generateRandomMeal();

console.log(meal);

That is the difference between the projects and lecture. The lecture aim to teach you a concept, where as the projects you have to implement what you learned.

There isn’t much you can do about it, but coming up with solutions (for the projects) is a massive part of programming. Programming is mostly problem solving. And learning problem solving is something that takes time and practice. The projects will definitely make you a better programmer.

just take your time with the projects. Ask yourself: What I am doing? And why? What am I attempting to implement? What should the final result be? That sort of thing.

2 Likes