Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!