Meal Maker - cannot find where i did it wrong

let menu = {
  _courses: {
    appetizers: [],
    mains: [],
    desserts: [],
    },
    get appetizers() {
return this._courses.appetizers
    },
    set appetizers (appetizers) {
return this._courses.appetizers = appetizers
    },
    get mains() {
return this._courses.mains
    },
    set mains(mains) {
return this._courses.mains = mains
    },
    get desserts() {
return this._courses.desserts
    },
    set desserts(desserts) {
return 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() {
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}, ${dessert.name}, The price is ${totalPrice}`;
    }
};  
    menu.addDishToCourse("appetizers","ameijoas", 6.80);
    menu.addDishToCourse("appetizers", "croquetes", 3.80);
    menu.addDishToCourse("appetizers", "camarĂŁo", 8.00);

    menu.addDishToCourse("mains", "Bacalhau com broa", 13.50);
    menu.addDishToCourse("mains", "Arroz de pato", 15.00);
    menu.addDishToCourse("mains", "Polvo á Lagareiro", 18.50);

    menu.addDishToCourse("Dessert", "Arroz doce", 4.50);
    menu.addDishToCourse("Dessert", "Mousse", 4.50);

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

error : /home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:52
menu.addDishToCourse(“appetizers”,“ameijoas”, 6.80);
^

TypeError: menu.addDishToCourse is not a function

Hey, @blorena. Welcome to the forums!

This is the error you’re getting, right? There’s a small typo in the method name.

While declaring the method, you have named it as addDishtoCourse and while calling the method, you’re using the name addDishToCourse and that’s why you’re getting the error!

It’s a very subtle typo and sometimes typos like this slip in without us noticing. Always double check the name of the method you’ve declared and the name of the method you’re calling.

Does that help?

EDIT:

A TypeError usually tries to inform us that we’re trying to do something with a value that is not allowed.

You’re trying to call a method which was never created. And that is not allowed, hence you see the error.

2 Likes