Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
Went over the whole thing several times but still can't find the mistake

This code is from a tutorial. It kept giving weird errors and now it's stuck at

SyntaxError: Unexpected token }

I followed the tutorial closely but I still can't locate the error. P.S Apparently I need to add a certain number of words to the description to be able to submit the question so this is just me doing that, I really have nothing else to say. Thank you.

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(appt) {
    return this._courses.appetizers = appetizers;
  },
  set mains(mains) {
    return this._courses.mains = mains;
  },
  set desserts(dess) {
    return this._courses.desserts = desserts,
  },
  get courses() {
    return {
      appetizers: this._courses.appetizers;
      mains: this._courses.mains;
      desserts: this._courses.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 randomI = Math.floor(Math.random() * dishes.length);
    return dishes[randomI];
  },
  generateRandomMeal() {
    const appetizer = this.getRandomDishFromCourse(appetizers);
    const main = this.getRandomDishFromCourse(main);
    const dessert = this.getRandomDishFromCourse(desserts);
    const totalPrice = appetizer.price + main.price + dessert.price;
    return `Your mean is ${appetizer.name}, ${main.name} and ${dessert.name}, and the total price is ${totalPrice}`
  },
};



menu.addDishToCourse('appetizers', 'salad', 4)
menu.addDishToCourse('appetizers', 'wings', 3)
menu.addDishToCourse('appetizers', 'fries', 5)

menu.addDishToCourse('mains', 'steak', 10)
menu.addDishToCourse('mains', 'kebab', 11)
menu.addDishToCourse('mains', 'cizbiz', 9)

menu.addDishToCourse('desserts', 'ice cream', 4)
menu.addDishToCourse('desserts', 'cake', 5)
menu.addDishToCourse('desserts', 'coffee', 4)


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

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ok, so I have found many errors here

line 17 should be: return this._courses.appetizers = appt;

appt is the argument passed in to the function

line 23 should be: return this._courses.desserts = dess;

Again, dess is the argument passed in to the function. Also, the statement needs to end witha semicolon, not a comma.

lines 27 - 29: The lines need to end with commas and not semicolons. It is returning an object, so the properties of the object need to be seperated by commas, not semicolons.

lines 34 - 35: Same issue, returning an object. Need to seperate properties with commas instead of semicolons.

lines 46 - 48: The variables passed into the functions do not exist. The arguments for that function should be strings. So change those variables to strings instead. Also, make sure to change main to "mains" on line 48.

You should learn some debugging. Either run the code with Node.js or put it in a script tag in HTML and run it in the browser. Then you can see the errors produced which usually show you exactly where the problems are.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda