Meal Maker Project Price logs as NaN

Hello, everyone. I’m a programming noob that just started this journey last month. I worked my way through the Meal Maker project, and everything logs correctly except for the price. When calling the generateRandomMeal method, it logs the correct random appetizer, main, and dessert. However, when it gets to the price it says it is “NaN.” I individually tested all my other functions, and they work as expected. Needless to say, for some reason that I cannot comprehend, the totalPrice variable I created does not reflect the prices but rather undefined. Any pointers would be incredibly appreciated.

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) {
    if (typeof appetizers === 'string') {
      return this._courses.appetizers = appetizers
    };
  },
  set mains(mains) {
    if (typeof mains === 'string') {
      return this._courses.mains = mains
    };
  },
  set desserts(desserts) {
    if (typeof desserts === 'string') {
      return this._courses.appetizers = desserts
    };
  },
  get courses() {
    return {
      appetizers: this._courses.appetizers,
      mains: this._courses.mains,
      desserts: this._courses.desserts,
    }
  },
  addDishToCourse(courseName, dishName, dishPrice) {
   const dish = {
     name: dishName,
     price: dishPrice,
   };
   if (courseName === 'appetizers') {
     return this._courses.appetizers.push(dish.name);
     console.log(dish)
   } else if (courseName === 'mains') {
     return this._courses.mains.push(dish.name);
   } else if (courseName === 'desserts') {
     return this._courses.desserts.push(dish.name);
   } else {
     console.log('This is not a valid course. Please try again.');
   }
  },
 getRandomDishFromCourse(courseName) {
   const dishes = this._courses[courseName];
 let i = Math.floor(Math.random() * dishes.length);
   return dishes[i];
 },
 generateRandomMeal() {
   const appetizer = this.getRandomDishFromCourse('appetizers');
   const main = this.getRandomDishFromCourse('mains');
   const dessert = this.getRandomDishFromCourse('desserts');
   const totalPrice = appetizer.price + main.price + dessert.price;
   console.log(`Your meal consists of ${appetizer} as your appetizer, ${main} for the entree, and ${dessert} as the final course. The total price for your meal will be $${totalPrice}.`);
 },
};

menu.addDishToCourse('appetizers', 'Mozzarella Sticks', 5.50);

menu.addDishToCourse('appetizers', 'Chicken Wings', 7.00);

menu.addDishToCourse('appetizers', 'Cheese Fries', 4.50);

menu.addDishToCourse('appetizers', 'Fried Pickles', 6.00);

menu.addDishToCourse('mains', 'Bacon Cheeseburger', 10.50);

menu.addDishToCourse('mains', 'Filet Mignon', 18.00);

menu.addDishToCourse('mains', 'Fish Tacos', 12.00);

menu.addDishToCourse('mains', 'Omelette', 8.50);

menu.addDishToCourse('desserts', 'Sundae', 5.00);

menu.addDishToCourse('desserts', 'Strawberry Cheesecake', 6.50);

menu.addDishToCourse('desserts', 'Molten Chocolate Cake', 8.00);

menu.addDishToCourse('desserts', 'Banana Split', 7.50);

menu.generateRandomMeal();

You may need to review the addDishToCourse function and what you are pushing in the array :wink:

I ran circles in my head trying to figure out what was wrong, and it was as simple as the pushed array being too specific… After changing the pushed array from being dish.name to simply dish for all three courses, the price of each was pushed to the array, allowing it to be defined by later functions. Running the generateRandomMeal() function logged [Object Object] for each food item. Thankfully, I realized the console.log message needed an update to be variable.name rather than just the variable. The six quick changes in my code are italicized, and now all food items and price log as normal. Thank you so much for the assist, @patmol6 :smiley:

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) {
    if (typeof appetizers === 'string') {
      return this._courses.appetizers = appetizers
    };
  },
  set mains(mains) {
    if (typeof mains === 'string') {
      return this._courses.mains = mains
    };
  },
  set desserts(desserts) {
    if (typeof desserts === 'string') {
      return this._courses.appetizers = desserts
    };
  },
  get courses() {
    return {
      appetizers: this._courses.appetizers,
      mains: this._courses.mains,
      desserts: this._courses.desserts,
    }
  },
  addDishToCourse(courseName, dishName, dishPrice) {
   const dish = {
     name: dishName,
     price: dishPrice,
   };
   if (courseName === 'appetizers') {
     return this._courses.appetizers.push(*dish)*;
   } else if (courseName === 'mains') {
     return this._courses.mains.push(*dish*);
   } else if (courseName === 'desserts') {
     return this._courses.desserts.push(*dish*);
   } else {
     console.log('This is not a valid course. Please try again.');
   }
  },
 getRandomDishFromCourse(courseName) {
   const dishes = this._courses[courseName];
 let i = Math.floor(Math.random() * dishes.length);
   return dishes[i];
 },
 generateRandomMeal() {
   const appetizer = this.getRandomDishFromCourse('appetizers');
   const main = this.getRandomDishFromCourse('mains');
   const dessert = this.getRandomDishFromCourse('desserts');
   const totalPrice = appetizer.price + main.price + dessert.price;
   console.log(`Your meal consists of ${*appetizer.name*} as your appetizer, ${*main.name*} for the entree, and a ${*dessert.name*} as the final course. The total price for your meal will be $${totalPrice.toFixed(2)}.`);
 },
};

menu.addDishToCourse('appetizers', 'Mozzarella Sticks', 5.50);

menu.addDishToCourse('appetizers', 'Chicken Wings', 7.00);

menu.addDishToCourse('appetizers', 'Cheese Fries', 4.50);

menu.addDishToCourse('appetizers', 'Fried Pickles', 6.00);

menu.addDishToCourse('mains', 'Bacon Cheeseburger', 10.50);

menu.addDishToCourse('mains', 'Filet Mignon', 18.00);

menu.addDishToCourse('mains', 'Fish Tacos', 12.00);

menu.addDishToCourse('mains', 'Omelette', 8.50);

menu.addDishToCourse('desserts', 'Sundae', 5.00);

menu.addDishToCourse('desserts', 'Strawberry Cheesecake', 6.50);

menu.addDishToCourse('desserts', 'Molten Chocolate Cake', 8.00);

menu.addDishToCourse('desserts', 'Banana Split', 7.50);

const meal = menu.generateRandomMeal();

meal;