Meal Maker

This is crazy but I can’t find why I am getting an error like this. I even deleted portions of my code and followed the examples to a T.

Blockquote
/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:45
const appetizer = this.getRandomDishFromCourse(‘appetizers’);
^
TypeError: this.getRandomDishFromCourse is not a function
at Object.generateRandomMeal (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:45:28)
at Object. (/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:54:17)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)

const menu = {
  _courses: {
    appetizers: [{tators: 2.99}, {chips: 5.66}],
    mains: [{pizza: 12.99}, {steak: 15.66}],
    desserts: [{sundae: 2.99}, {icecream: 5.66}]
  },
  get appetizers() {
    return this._courses.appetizers;
  },
  set appetizers(appetizer) {
    return this._courses[appetizers].push(appetizer);
  },
  get mains() {
    return this._courses.mains;
  },
  set mains(main) {
    return this._courses[mains].push(main);
  },
  get desserts() {
    return this._courses.desserts;
  },
  set desserts(dessert) {
    return this._courses[desserts].push(dessert);
  },
  get courses() {
    return{
      appetizers: this._courses.appetizers,
      mains: this._courses.mains,
      desserts: this._courses.desserts
    }
  },
  addDishToCourse: (courseName, dishName, dishPrice) => {
    const dish = {
      dishName: dishPrice,
    }
    return this.courseName(dish);
  },
  getRandomDishFromCourse: function(courseName) {
    const dishes  = this.courseName();
    const randomIndex = Math.floor(Math.random() * dishes.length);
    
    return dishes[randomIndex];
  },
  generateRandomMeal: () => {
    const appetizer = this.getRandomDishFromCourse('appetizers');
    const mains = this.getRandomDishFromCourse('mains');
    const desserts = this.getRandomDishFromCourse('desserts');
    const totalPrice = appetizer.price + mains.price + desserts.price;

    return `Your meal is ${appetizer.name}, ${main.name},  ${desserts.name} The price is $${totalPrice}.`;
  }
}

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

1 Like

Why confuse the situation with a blend of old and new syntax. Using the old object syntax and arrow functions is perfectly valid, but moot when we have ES6 methods.

generateRandomMeal () {

}
2 Likes

Thanks I figured it out that night forgot to come back.

1 Like