Meal Maker Project

Whenever I enter my code it says that getRandomDishFromCourse is not defined but it is a function and it was defined earlier in the code. PLEASE HELP.

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){
this._courses.appetizers = appetizers;
},
set
mains(mains){
this._courses.mains = mains;
},
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,
};
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() {
var appetizer = getRandomDishFromCourse('appetizers');
var main = getRandomDishFromCourse('mains');
var dessert = getRandomDishFromCourse('desserts');
const totalPrice = appetizer.price + main.price + dessert.price
return `You ate ${appetizer.name}, ${main.name}, and ${dessert.name}. Your total price is ${totalPrice}.`;
},
};
menu.addDishToCourse('appetizers', 'Garlic Bread', 2.50);
menu.addDishToCourse('appetizers', 'Fries', 4.00);
menu.addDishToCourse('appetizers', 'Salad', 4.50);
menu.addDishToCourse('mains', 'Pizza', 9.00);
menu.addDishToCourse('mains', 'Pasta', 8.00);
menu.addDishToCourse('mains', 'Eggplant', 10.00);
menu.addDishToCourse('desserts', 'IceCream', 5.00);
menu.addDishToCourse('desserts', 'Chocolate Cake', 6.00);
menu.addDishToCourse('desserts', 'Blueberry Pie', 8.00);
let meal = menu.generateRandomMeal();
console.log(meal);

Remember, just because we define things in the same class doesn’t mean we have automatic access to everything else in there.

Hint

Use “this” keyword

While your reply did help me think about this more I still can’t find out where I would but the “this” keyword because when I put it in the end in the variable “meal” it won’t work. Can you be a little more specific?

Sure. You want to use the getRandomDishFromCourse method in your generateRandomMeal method.

const randomclass= {
  method1(){
    //content
  }
  method2(){
   result = this.method1();
   console.log(result);
  }
};
hint

Use this.getRandomDishFromCourse