Meal maker

hello I just completed Meal maker but I keep having syntax error even after going over it 3 times and using the help video. I cannot figure out what is wrong. can any experienced programmers point out my mistakes?
here is my code:

const menu = {

  _courses: {

  appitzers:[],

  mains:[],

  desserts:[],

  },

  get appetizers() {

    return this._courses.appetizers;

  }, 

  get mains() {

    return this._courses.mains;

  },

  get desserts() {

    return this._courses.desserts;

  },

  set appitizers(appetizersIn) {

    return this._courses.appetizers = appetizers;

  },

  set mains(mainsIn) {

    return this._courses.mains = mains;

  },

  set desserts(dessertsIn) {

    return this._courses.desserts = desserts

  },

  get courses () {

    return {

      appitizers: this.appetizers,

      mains: this.mains,

      desserts: this.desserts,

    },

  };

 addDishToCourse(courseName, dishName, dishPrice) { const dish = {

   name: dishName

   price: dishPrice

   },

  this._courses[courseName].push(dish);

  };

  getRandomDishFromCourse: function () {

    const dishes = this._courses[courseName];

    const randomIndex = Math.floor(Math.random() * dishes.length);

    return dishes[randomIndex];

  };

  generateRandomMeal: function() {

    const appetizer = this.getRandomDishFromCourse('appetizers')

    const mains = this.getRandomDishfromCourse('mains')

    const desserts = this.getRandomDishfromCourse('desserts')

    const totalPrice = appetizer.price + main.price + dessert.price

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

  },

}; 

menu.addDishToCourse('appetizers', 'Lobster Bisque', 5.30);

menu.addDishToCourse('appetizers', 'Calamari', 2.30)

menu.addDishToCourse('mains', 'Shrimp Linguini Alfredo', 8.75);

menu.addDishToCourse('mains'. 'Walt Favorite Shrimp', 7.20);

menu.addDishToCourse('desserts', 'Fudge Brownie Sundae', 4.50);

menu.addDishToCourse('desserts', 'Lava Cookie', 6.00)

let meal = menu.generateRandomMeal();

console.log(meal);

Here is the error:
/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:31
};
^
SyntaxError: Unexpected token }
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)

Hi @codemasterzk72
after taking a first short look, I see several syntax errors here: Sometimes you’re using semicolons where you should use commas and vice versa.
Also, you need to reference variables or keys with the keyword this.

do you mean in the return where i start making my sentence structure your meal is... is that where i need this, because everywhere else i have it clearly labeled. also how do you know where to use semicolons and how do you know where to use commas, i never understood where to apply it even after watching the videos by programmers.

Hi @codemasterzk72
within an object, you should seperate the properties with commas, which you did most of the times. Here you didn’t:

This cannot work due to misspelling in two cases. Same for the other setters. But you don’t use the setters, so that doesn’t cause your trouble:

These properties need comma separation:

This is a method, not a key. Don’t use a colon. And no need for the function keyword. Look how you did it with the addDishToCourse method.

Same for generateRandomMeal.

No. You’re using variables you defined within the method there. That’s fine.
This is what I meant:

get courses closes here? Are we still inside the object menu? Because if we are then that semicolon is wrong.

  get courses () {
    return
    {

      appitizers: this.appetizers,

      mains: this.mains,

      desserts: this.desserts,

    },

  };

Is this the right property or a typo? The same in _courses

appitizers

Start checking these, then let us know and we may continue :slight_smile:

still stuck but here is what it looks like now after your 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(appetizersIn) {

   this._courses.appetizers = appetizers;

  },

  set mains(mainsIn) {

   this._courses.mains = mains;

  },

  set desserts(dessertsIn) {

   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

   },

  this._courses[courseName].push(dish)

  },

  getRandomDishFromCourse() {

    const dishes = this._courses[courseName];

    const randomIndex = Math.floor(Math.random() * dishes.length)

    return dishes[randomIndex];

  },

  generateRandomMeal: function () {

    const appetizer = this.getRandomDishFromCourse('appetizers')

    const mains = this.getRandomDishfromCourse('mains')

    const desserts = this.getRandomDishfromCourse('desserts')

    const totalPrice = appetizer.price + main.price + dessert.price

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

  },

}; 

menu.addDishToCourse('appetizers', 'Lobster Bisque', 5.30);

menu.addDishToCourse('appetizers', 'Calamari', 2.30)

menu.addDishToCourse('mains', 'Shrimp Linguini Alfredo', 8.75);

menu.addDishToCourse('mains'. 'Walt Favorite Shrimp', 7.20);

menu.addDishToCourse('desserts', 'Fudge Brownie Sundae', 4.50);

menu.addDishToCourse('desserts', 'Lava Cookie', 6.00)

let meal = menu.generateRandomMeal();

console.log(meal);

incidentally this meal is what i normally eat at Red Lobster. just a little bit of trivia.

Hi @codemasterzk72
could you please format your code and specify what problems you encounter now?

Its the same error as the previous posts, syntax errors and extra tokens. as for where they occur, i don’t know which is why i posted the whole thing.

Could you format your code, please.

done see previous posting

^
The issue is still there. Check the other methods, too: Commas for key separation, semicolons for ending statements within methods or functions.

^
This issue is also still there:

^
getRandomDishFromCourse doesn’t have a parameter. courseName is undefined.

^
Syntax error: Compare it to the others.

here is my new code and the new error is unexpected identifier in Get Appetizers. what does unexpected identifier mean?

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(appetizersIn) {
   this._courses.appetizers = appetizers;
  },
  set mains(mainsIn) {
   this._courses.mains = mains;
  }
  set desserts(dessertsIn) {
   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,
   }
  this._courses[courseName].push(dish)
  }
  getRandomDishFromCourse() {
    const dishes = this._courses[courseName];
    const randomIndex = Math.floor(Math.random() * dishes.length)
    return dishes[randomIndex];
  }
  generateRandomMeal() {
    const appetizers = this.getRandomDishFromCourse('appetizers')
    const mains = this.getRandomDishfromCourse('mains')
    const desserts = this.getRandomDishfromCourse('desserts')
    const totalPrice = appetizer.price + main.price + dessert.price
    return `Your meal is ${appetizer.name}, ${main.name}, and ${dessert.name}. The price is ${totalPrice}`;
  }
}; 

menu.addDishToCourse('appetizers', 'Lobster Bisque', 5.30);
menu.addDishToCourse('appetizers', 'Calamari', 2.30)

menu.addDishToCourse('mains', 'Shrimp Linguini Alfredo', 8.75);
menu.addDishToCourse('mains', 'Walt Favorite Shrimp', 7.20);

menu.addDishToCourse('desserts', 'Fudge Brownie Sundae', 4.50);
menu.addDishToCourse('desserts', 'Lava Cookie', 6.00);

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

It means syntax error:

I am very close I think to solving this, here is the new error. now i know what to look for but it is not clear on which bracket is causing the error.

/home/ccuser/workspace/learn-javascript-objects-meal-maker/app.js:31
  }
  ^
SyntaxError: Unexpected token }
    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)

here is my code.

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(appetizersIn) {

   this._courses.appetizers = appetizers;

  },

  set mains(mainsIn) {

   this._courses.mains = mains;

  },

  set desserts(dessertsIn) {

   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,

    },

  this._courses[courseName].push(dish)

  }

  getRandomDishFromCourse() {

    const dishes = this._courses[courseName];

    const randomIndex = Math.floor(Math.random() * dishes.length)

    return dishes[randomIndex];

  }

  generateRandomMeal() {

    const appetizers = this.getRandomDishFromCourse('appetizers')

    const mains = this.getRandomDishfromCourse('mains')

    const desserts = this.getRandomDishfromCourse('desserts')

    const totalPrice = appetizer.price + main.price + dessert.price

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

  },

}; 

menu.addDishToCourse('appetizers', 'Lobster Bisque', 5.30);

menu.addDishToCourse('appetizers', 'Calamari', 2.30)

menu.addDishToCourse('mains', 'Shrimp Linguini Alfredo', 8.75);

menu.addDishToCourse('mains', 'Walt Favorite Shrimp', 7.20);

menu.addDishToCourse('desserts', 'Fudge Brownie Sundae', 4.50);

menu.addDishToCourse('desserts', 'Lava Cookie', 6.00);

let meal = menu.generateRandomMeal();

console.log(meal);

Your main problem is still the issue with commas and semicolons. And I guess the syntax error is still caused by a missing comma.
Separate your properties and methods with commas. And don’t use commas within a method – outside an object. Many of the issues I pointed out earlier are still there. Just one example, you should be able to do the rest of that yourself:

I thank all of you for your help. I think I can figure it out from here. sorry for the many questions, this is more involved than i thought but I am loving learning it.

1 Like

I would recommend you copy your code in Fiddle for example. It highlights the simple syntax errors like missing parenthesis or wrong commas right where they appear. Then you can concentrate on the functionality of your code.

1 Like

is it free to use. that would be helpful, thank you.

Yes, the basic functionality is free. That’s well fit for simple debugging.