Meal Maker issues, please help!

Hello! I started studying JavaScript in November and I have been working very diligently to learn this language. I have completed a few projects, however, I am stuck on this one and I cannot seem to figure out what I am doing wrong. Please help me! https://www.codecademy.com/courses/introduction-to-javascript/projects/meal-maker is the project, and below is the code I have made. I keep getting an error on line 39. What am I doing wrong? Thank you for your time!

const menu = {

_courses: {

appetizers: [],

mains: [],

desserts: [],

}, get appetizers() {

return this._courses.appetizers = appetizers;

},

set appetizers(appetizerIn) {

}, get mains() {

return this._courses.mains = mains;

},

set mains(mainsIn) {

}, get desserts() {

return this._courses.desserts = desserts;

},

set 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 randomIndex = Math.floor(Math.random() * dishes.length);

return dishes[randomIndex];

},

generateRandomMeal() {

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

const meal = this.getRandomDishFromCourse('meals');

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.00);

menu.addDishToCourse(‘appetizers’, ‘wings’, 5.00);

menu.addDishToCourse(‘appetizers’, ‘fries’, 2.50);

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

menu.addDishToCourse(‘mains’, ‘chicken’, 9.00);

menu.addDishToCourse(‘mains’, ‘salmon’, 10.50);

menu.addDishToCourse(‘desserts’, ‘baklava’, 6.00);

menu.addDishToCourse(‘desserts’, ‘ice cream’, 4.00);

menu.addDishToCourse(‘desserts’, ‘cake’, 5.50);

const meal = menu.generateRandomMeal();

console.log(meal);

You need to redo most of the set methods.
The purpose of the set methods (functions) is to change the objects’ variables (properties).

Also, appetizers is misspelled on the following line:

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

 

In the addDishToCourse function,
you don’t need the return in front of this._courses[courseName].push(dish);
(The purpose of that function is to change what’s in the object, not to get an output.)

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

  get appetizers() {
    return this._courses.appetizers = appetizers;
  },

  set appetizers(appetizerIn) {
  }, 

  get mains() {
    return this._courses.mains = mains;
  },

  set mains(mainsIn) {
  }, 

  get desserts() {
    return this._courses.desserts = desserts;
  },

  set 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 randomIndex = Math.floor(Math.random() * dishes.length);
    return dishes[randomIndex];
  },

  generateRandomMeal() {
    const appetizer = this.getRandomDishFromCourse('appetixers');
    const meal = this.getRandomDishFromCourse('meals');
    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.00);
menu.addDishToCourse(‘appetizers’, ‘wings’, 5.00);
menu.addDishToCourse(‘appetizers’, ‘fries’, 2.50);
menu.addDishToCourse(‘mains’, ‘steak’, 12.00);
menu.addDishToCourse(‘mains’, ‘chicken’, 9.00);
menu.addDishToCourse(‘mains’, ‘salmon’, 10.50);
menu.addDishToCourse(‘desserts’, ‘baklava’, 6.00);
menu.addDishToCourse(‘desserts’, ‘ice cream’, 4.00);
menu.addDishToCourse(‘desserts’, ‘cake’, 5.50);

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

Thank you! I did go back and start it over from scratch. It works fine now :slight_smile:

Hi, In the javascript Meal Maker problem I am getting the error that price is undefined in my code. Can anyone of you help me out with it. why I am getting the error?

const menu={
_course:{
appetizers:,
mains:,
desserts:
},
get courses(){
return {
appetizers: this.appetizer,
mains:this.mains,
desserts:this.dessets
};
},
get appetizers(){
return this._course.appetizers;
},
get mains(){
return this._course.mains;
},
get desserts(){
return this._course.desserts;
},
addDishToCourse(courseName,dishName,dishPrice){
const dish={
name:dishName,
price:dishPrice
};
this._course[courseName].push(dish);
},

getRandomDishFromCourse(courseName){
const dishes=this._course[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 of these items are $${totalPrice};
}
};

menu.addDishToCourse(‘appetizers’, ‘Caesar Salad’, 4.25);
let meal=menu.generateRandomMeal();
console.log(meal);

You haven’t created any mains or desserts yet
so there’s an error when if tries to do
main.price and dessert.price in the generateRandomMeal function.

Also, there’s typos here:

appetizer should be appetizers
and
dessets should be desserts

Spelling errors cause me trouble all the time.