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

229
Views
I want the user to guess a random number but every time I refresh the page a new random number generates

I need to create a random number that the user has to guess. When I refresh the page it appears the generate a new random number.

var userPrompt = prompt("Guess a number");
var ran = Math.floor(Math.random() * 10);
    
function ranNumGame(ran) {
    
      if (userPrompt == ran) {
        return "Congrats";
      }
      else if (ran < userPrompt) {
        return "Lower";
      }
      else if (ran > userPrompt) {
        return "Higher";
      }
}
    
console.log(ranNumGame(ran));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

var randomNumber = Math.floor(Math.random() * 10);
var userInput = prompt("Pick a number between 0 and 10");

while (userInput != randomNumber) {
  alert("nope");

  if (userInput < randomNumber) {
    userInput = prompt("guess higher");
  } else if (userInput > randomNumber) {
    userInput = prompt("guess lower");
  } else if (userInput == randomNumber) {
    alert("congrats");
    console.log("congrats");
  }
}
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!