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

231
Views
first JS random number to guess game

I have slight problem with my first guessing game, it should draw random number between 1-10, but it return "1" every time. What's wrong in here? Thanks.

function guessGame() {
  let randomNr = Math.floor(Math.random() * 11);
  console.log(randomNr)
  let guess;
  do {
    guess = prompt("Guess number 1-10");
    console.log(guess, randomNr);
    if (randomNr > guess) {
      console.log("You guessed too low");
    } else if (randomNr < guess) {
      console.log("Guess was too high");
    }
  } while (guess !== randomNr);
  console.log("You Won");
}

guessGame();

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It appears your random number generator is working correctly. One thing to note though since you define randomNr outside of the do while loop it will only create a random number when guessGame() if first run, but it won't change the number on each guess. If you would like it to change number after each guess you could move let randomNr = Math.floor(Math.random() * 11); into the do while loop.

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!