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

133
Visualizações
Javascript simple if/else statement Quiz Game with 5 questions that outputs results at the end

Anyone care to help me get this code running correctly? Just simple if/else statements Javascript. I have tried attaching a "do {" before each of the next questions, but I couldn't get that to work. It keeps saying that "Uncaught SyntaxError: Unexpected end of input".

alert("Welcome to the 'Guess that Celebrities Age' Game! Let's see how many out of 5 you 
can guess right.")
let guess = 0;
let guess1 = 0;
let guess2 = 0;
let guess3 = 0;
let guess4 = 0;
let guess5 = 0;
let winsCounter = 0;
let losesCounter = 0;
do {
  guess = prompt("How old is Cher?");
  if (guess == 75) {
  alert("Correct! Cher is 75 years old. You guessed the number in tries.");
    winsCounter++;
}
  else {
    alert("Wrong! Sorry, better luck next time.");
    losesCounter++;
  }


 guess2 = prompt("How old is Elton John?");
  if (guess2 == 74) {
  alert("Correct! Elton John is 74 years old. You guessed the number in tries.");
    winsCounter++;
}
  else {
    alert("Wrong! Sorry, better luck next time.");
    losesCounter++;
  }


  guess3 = prompt("How old is Doja Cat?");
  if (guess3 == 26) {
  alert("Correct! Doja Cat is 26 years old. You guessed the number in tries.");
    winsCounter++;
}
  else {
    alert("Wrong! Sorry, better luck next time.");
    losesCounter++;
  }


  guess4 = prompt("How old is Christina Ricci?");
  if (guess4 == 42) {
  alert("Correct! Christina Ricci is 42 years old. You guessed the number in tries.");
    winsCounter++;
}
  else {
    alert("Wrong! Sorry, better luck next time.");
    losesCounter++;
  }


  guess5 = prompt("How old is Seth Rogan?");
  if (guess5 == 39) {
  alert("Correct! Seth Rogan is 39 years old. You guessed the number in tries.");
    winsCounter++;
}
  else {
   alert("Wrong! Sorry, better luck next time.");
    losesCounter++;
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your do statement is incorrect. It needs the while keyword at the end.

So, you can change your code to the template below to get it working.

let i = 0;
do {
  console.log(i);
  i++;
} while (i < 5)

Basically, after the do keyword, you can add your code in the curly braces.

However, at the end of the curly braces (}), you can then add the while keyword, and a boolean condition in the brackets (parentheses).


Edit: Here is the documentation for do...while.

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