Meal maker undefined issue

hello i am having issues with my code, everytime i try and run it it returns “cannot read property ‘appetizers’ of undefined”.
code posted below.

const menu = {
_courses: {
‘appetizers’:,
‘mains’:,
‘desserts’:
},
get appetizers() {
return this._courses.appetizers;
},
set appetizers(appetizers) {
this._courses.appetizers = appetizers;
},
get mains() {
return this._courses.mains;
},
set mains(mains) {
this._courses.mains = mains;
},
get desserts() {
return this._courses.desserts;
},
set desserts(desserts) {
this._courses.desserts = desserts;
},
get courses() {
return {
appetizers: this.appetizers,
mains: this.mains,
desserts: this.desserts
}
},

addDishToCourse (courseName, dishName, dishPrice) {
  const dish = {
    name: dishName,
    price: dishPrice
  };
  this._courses[courseName].push(dish);
},
getRandomDishFromCourse (courseName) {
  const dishes = this._courses[courseName];
  const index = Math.floor(Math.random() * dishes.length);
  return this._course[courseName][index]
},
generateRandomMeal () {
  const appetizer = this.getRandomDishFromCourse('appetizers');
  const main = this.getRandomDishFromCourse('mains');
  const dessert = this.getRandomDishFromCourse('desserts');
  const totalPrice = (appetizer.price + main.price + dessert.price);
}

}
menu.addDishToCourse(‘mains’, ‘tacos’, 7.55);
menu.addDishToCourse(‘appetizers’, ‘cheese Dip’, 8);
menu.addDishToCourse(‘desserts’, ‘tres leches’, 10);
menu.addDishToCourse(‘appetizers’, ‘artichoke dip’, 6);
menu.addDishToCourse(‘appetizers’, ‘fried green tomatoes’, 6.77);
menu.addDishToCourse(‘mains’, ‘fried chicken’, 12);
menu.addDishToCourse(‘mains’, ‘steak’, 20);
menu.addDishToCourse(‘desserts’, ‘ice cream’, 6);
menu.addDishToCourse(‘desserts’, ‘cupcake’, 4);
let meal = menu.generateRandomMeal();
let meal2 = menu.generateRandomMeal();
console.log(meal)
console.log(meal2)

1 Like

figured out my issues, i had “course” instead of “courses” SMH

1 Like

Lol it’s happened to me more times than I can count. No worries.

Welcome to the forums :slight_smile:

For future reference, remember to press </> before pasting all that code!

thanks so much! i am actually having another issue, code is running fine now, but instead of posting the name of the dish in my final product it says [object Object] for each of the menu items. i am still getting correct price differences but the food just wont show up.

const menu = {
    _courses: {
      appetizers:[],
      mains:[],
      desserts:[]
    }, 
    get appetizers() {
        return this._courses.appetizers;
      },
      set appetizers(appetizers) {       
         this._courses.appetizers = appetizers;
      },
      get mains() {
        return this._courses.mains;
      },
      set mains(mains) {
       this._courses.mains = mains;
      },
      get desserts() {
        return this._courses.desserts;
      },
      set desserts(desserts) {
       this._courses.desserts = desserts;
      },
      get courses() {
        return {
        appetizers: this.appetizers,
        mains: this.mains,
        desserts: this.desserts
        }
      },

    addDishToCourse (courseName, dishName, dishPrice) {
      const dish = {
        name: dishName,
        price: dishPrice
      };
      this._courses[courseName].push(dish);
    },
    getRandomDishFromCourse (courseName) {
      const dishes = this._courses[courseName];
      const index = Math.floor(Math.random() * dishes.length);
      return this._courses[courseName][index]
    },
    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 `${appetizer} first, ${main} to follow, and end it with ${dessert}. Your total will be ${totalPrice}`
    }
  }
  menu.addDishToCourse('mains', 'tacos', 7.55);
  menu.addDishToCourse('appetizers', 'cheese Dip', 8);
  menu.addDishToCourse('desserts', 'tres leches', 10);
  menu.addDishToCourse('appetizers', 'artichoke dip', 6);
  menu.addDishToCourse('appetizers', 'fried green tomatoes', 6.77);
  menu.addDishToCourse('mains', 'fried chicken', 12);
  menu.addDishToCourse('mains', 'steak', 20);
  menu.addDishToCourse('desserts', 'ice cream', 6);
  menu.addDishToCourse('desserts', 'cupcake', 4);
  let meal = menu.generateRandomMeal();
  let meal2 = menu.generateRandomMeal();
  console.log(meal)
  console.log(meal2)

hey sorry again, but i figured out the code for myself with a little bit more tinkering. in my final string i had written “appetizer” instead of “appetizer.name” etc.

Great! Personally I don’t trust myself to not write typos. I’m always checking my functions before I move on and I’ll leave a comment that says //tested, works with x dependencies