Https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-learn-javascript-syntax-objects/projects/meal-maker

This project ‘meal maker’ is very overwhelming
Till now I had this problem


this is the whole code:
const menu = {

_courses: {

appetizers: [],

mains: [],

desserts: [],

get appetizers() {

  return this._courses.appetizers;

},

set appetizers(appetizerIn) {

  this._courses.appetizers = appetizerIn;

},

get mains() {

  return this._courses.mains;

},

set mains(mainsIn) {

  this._courses.mains = mainsIn;

},

get desserts() {

  return this._courses.desserts;

},

set desserts(dessertsIn) {

  this._courses.desserts = dessertsIn;

}

},

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 index = Math.floor(Math.random() * dishs.length());

return dishes[index];

},

generateRandomMeal() {

const appetizer = this.getRandomDishFromCourse('appetizers');

const main = this.getRandomDishFromCourse('main');

const dessert = this.getRandomDishFromCourse('dessert');

const totalPrice = appetizer.price + main.price + dessert.price;

return `Your meal is ${appetizer.name}, ${main.name}, ${dessert.name} and the price is ${totalPrice}.`

}

};

menu.addDishToCourse(‘appetizers’, ‘salad’, 10);

Hello,

You have your getters and setters inside your _courses object, which is inside your menu object. Since the getters and setters are currently inside _courses, you wouldn’t need to specify this._courses.propertyname to access the properties that are also inside of the _courses object at the same level. You’d only need to use this.propertyname

If you moved your getters and setters to be the same level as the other properties in menu (for example, the same level as the _courses object, then you’d need to specify this._courses.propertyname like you’re doing now.

1 Like

Thanks :smiling_face_with_three_hearts:
this problem is solved but now I have another problem

Thanks alot for your effort , I found the solution and the program worked.
have a great day. :heart:

1 Like

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