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

153
Views
browser skips javascript do while

I have been trying to practice JavaScript after awhile withou using it. I am doing a simple voting exercise where users use numbers 1,2 or 3 in a window.prompt or a different number to finish the voting. Problem is, I have used a "do while" to create the loop and the browser doesn't seem to read it. It skips directly to the last "alert". What should I do? Code follows:

let end = false;

let votosFulano = 0;
let votosCicrano = 0;
let votosBeltrano = 0;

let mostVoted = "no votes yet";

do {
  let voto = window.prompt("Vote 1 for Fulano, 2 for Cicrano and 3 for Beltrano ou outro número para encerrar a votação");

  if (voto == 1) {
    votosFulano += 1;
    end = false;
  }

  if (voto == 2) {
    votosCicrano += 1;
    end = false;
  }

  if (voto == 3) {
    votosBeltrano += 1;
    end = false;

  }

  if (voto !== 1 && voto !== 2 && voto !== 3) {
    if (votosFulano > votosBeltrano && votosFulano > votosCicrano) {
      mostVoted = "Fulano";
    } else if (votosBeltrano > votosFulano && votosBeltrano > votosCicrano) {
      mostVoted = "Beltrano";
    } else if (votosCicrano > votosFulano && votosCicrano > votosBeltrano) {
      mostVoted = "Cicrano";
    }

    end = true;
  }
} while (end == false);

if (votosFulano == 0 && votosCicrano == 0 && votosBeltrano == 0) {
  alert("No votes");
} else {
  alert("Winner is " + mostVoted);
}

about 4 years ago · Juan Pablo Isaza
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!