Unexpected Identifier Error Code in JS Meal Maker

I’ve been working on Meal Maker and the following error message is occurring (the code is below the error message). I’ve commented out the method getRandomDishFromCourse(courseName) and then the error message moves on say the same thing about the next method generateRandomMeal()

/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:47
getRandomDishFromCourse(courseName) {
^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
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 : [],
    mains : [],
    dessert : [],
  },
    get appetizers() {
      return this._courses.appetizers;
    },
    get mains() {
      return this._courses.mains;
    },
    get desserts() {
      return this._courses.desserts;
    },
    set appetizers(appetizerIn) {
      this._courses.appetizers = appetizer;
    },
    set mains(mainIn) {
      this._courses.mains = main;
    },
    set desserts(dessertIn) {
      this.courses.desserts = dessert;
    },

    get courses() {
      return{
        appetizers: this.appetizers,
        mains: this.mains,
        desserts: this.desserts,
      }
    },

  addDishToCourse (courseName, dishName, dishPrice) {
  (!(courseName in this._courses)); 
    {
      this._courseName[courseName] }
    
    const dish = {
      courseName : [],
      name: dishName,
      price: dishPrice,
    };
    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('appetizer');
    const main 
    = this.getRandomDishFromCourse('main');
    const dessert 
    = this.getRandomDishFromCourse('dessert');
    const totalPrice = appetizer.price + main.price + dessert.price;
    return `Your meal is ${appetizer.name}, ${main.name}, ${dessert.name}. The price is $${totalPrice}.`;
  },
  };


menu.addDishToCourse('appetizer', 'salad', 4.00);
menu.addDishToCourse('appetizer', 'duck', 4.50);
menu.addDishToCourse('appetizer', 'soup', 3.50);

menu.addDishToCourse('main', 'steak', 24.00);
menu.addDishToCourse('main', 'fish', 16.00);
menu.addDishToCourse('main', 'pork', 20.00);

menu.addDishToCourse('dessert', 'pie', 7.00);
menu.addDishToCourse('dessert', 'icecream', 6.00);
menu.addDishToCourse('dessert', 'cheesecake', 7.00);

 const meal = 
 menu.generateRandomMeal()

console.log(meal);





When the error is at the beginning of a line, also check the line above:

  } // missing ,

getRandomDishFromCourse(courseName) {

you forgot a , to separate property value pairs.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.