Meal Maker error: TypeError: menu.addDishToCourse is not a function at Object.<anonymous>

Hi there, could someone help point out to me why I’m getting this error? I’ve written my code almost exactly like the walkthrough video and checked other questions in the forum, all of the functions I’ve written are in the menu object so i’m having issues understanding why I’m getting the error! any help would be appreciated! code below:

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  },
  get appetizers() {
    return this._courses.appetizers;
  },
  set appetizers(appetizerIn) {
    this._courses.appetizers = appetizersIn
  },
  get  mains() {
    return this._courses.mains;
  },
  set mains(mainsIn) {
    this._courses.mains = mainsIn
  },
  get desserts() {
    return this._courses.desserts;
  },
  set desserts(dessertsIn) {
    this._courses.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.RandomDishFromCourse("appetizers");
    const main = this.RandomDishFromCourse("mains");
    const dessert = this.RandomDishFromCourse("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}`;
  }
};

console.log(typeof menu._courses);

menu.addDishToCourse("appetizers", "Salad", 4.00);
menu.addDishToCourse("appetizers", "Halloumi Fries", 6.00);
menu.addDishToCourse("appetizers", "Potato Wedges", 4.50);

menu.addDishToCourse("mains", "Burger", 11.25);
menu.addDishToCourse("mains", "Lasagne", 9.50);
menu.addDishToCourse("mains", "Carbonara", 11.75);

menu.addDishToCourse("desserts", "Ice Cream", 6.25);
menu.addDishToCourse("desserts", "Brownie", 7.25);
menu.addDishToCourse("desserts", "Cheesecake", 5.50);

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

The error I’m getting is shown below:

Hello, and welcome to the forums!

JavaScript is case-sensitive, so addDishToCourse and addDishtoCourse are different. Double check the letter casing of it all.

1 Like

Thank you so much, I feel so silly for not having realised, I looked at the function names like 5 times and didn’t notice haha thank you so much for the warm welcome! I really do appreciate your help! I fixed the other errors that showed up in my code as well as I made a couple function name errors haha! Below is my updated working code if it can help anyone!:

const menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
  },
  get appetizers() {
    return this._courses.appetizers;
  },
  set appetizers(appetizerIn) {
    this._courses.appetizers = appetizersIn
  },
  get  mains() {
    return this._courses.mains;
  },
  set mains(mainsIn) {
    this._courses.mains = mainsIn
  },
  get desserts() {
    return this._courses.desserts;
  },
  set desserts(dessertsIn) {
    this._courses.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("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}, and ${dessert.name}, and the total price is ${totalPrice}`;
  }
};

menu.addDishToCourse("appetizers", "Salad", 4.00);
menu.addDishToCourse("appetizers", "Halloumi Fries", 6.00);
menu.addDishToCourse("appetizers", "Potato Wedges", 4.50);

menu.addDishToCourse("mains", "Burger", 11.25);
menu.addDishToCourse("mains", "Lasagne", 9.50);
menu.addDishToCourse("mains", "Carbonara", 11.75);

menu.addDishToCourse("desserts", "Ice Cream", 6.25);
menu.addDishToCourse("desserts", "Brownie", 7.25);
menu.addDishToCourse("desserts", "Cheesecake", 5.50);

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