Meal Maker Project

const menu = {

_courses: {

appetizers: [],

mains: [],

desserts: [],

},

get appetizers() {

return this._courses.appetizers;

},

set appetizers(item) {

this._courses.appetizers.push(item);

},

get mains() {

return this._coursesmains;

},

set mains(item) {

this._courses.mains.push(item);

},

get desserts() {

return this._courses.desserts;

},

set desserts(item) {

this._courses.desserts.push(item);

},

get coursesAvailable() {

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('appetizers');

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

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

const totalCost = appetizer[1] + main[1] + dessert[1];

return `Your appetizer: ${appetizer[0]}, main: ${main[0]}, dessert: ${dessert[0]}. Total Cost: ${totalCost}. Thank you, visit us again :)`

}

};

menu.addDishToCourse(‘appetizers’, ‘nachos’, 7.99);

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

menu.addDishToCourse(‘appetizers’, ‘mozarella sticks’, 8.99);

menu.addDishToCourse(‘mains’, ‘pasta’, 13.99);

menu.addDishToCourse(‘mains’, ‘pizza’, 12.99);

menu.addDishToCourse(‘mains’, ‘Enchilada and Chimichanga’, 14.99);

menu.addDishToCourse(‘desserts’, ‘fudge’, 6.99);

menu.addDishToCourse(‘desserts’, ‘brownie’, 4.99);

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

const meal = menu.generateRandomMeal();

console.log(meal);

Here’s my code for the challenge and everything seems to be fine, I think I’ve ironed out all the syntax errors but I’m not getting the desired output for some reason. I’d appreciate it if someone could help me out here. Below’s the output that I get:

Your appetizer: undefined, main: undefined, dessert: undefined. Total Cost: NaN. Thank you, visit us again :slight_smile:

I keep getting undefined for some reason, again any help will be much appreciated! Thanks in advance :slight_smile:

In your generateRandomMeal() method, notice that do this:

const totalCost = appetizer[1] + main[1] + dessert[1];

and this:

return `Your appetizer: ${appetizer[0]}, main: ${main[0]}, dessert: ${dessert[0]}. Total Cost: ${totalCost}. Thank you, visit us again :)`

You have to keep that these are objects, not arrays. You can’t do appetizer[1] for example. You should be doing appetizer.name and for the cost, appetizer.price.

Look back at the method that creates a dish:

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

See? your dish is an object with properties name and price.