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

162
Views
A JavaScript Program where a number is generated and the user tries to guess it. My Issue is input

I have the randomizer working, My issue is getting the user's input. I can't seem to figure out how to trigger the input. I used "window.alert" as well as "console.log" but nothing happens. I'm very new to this.

This is my HTML:

<DOCTYPE html>

<html>

    <body>

        <h2> Guessing For Random Numbers! </h2>
        <p> A random number between one (1) and ten (10) will be selected. Try to guess the 
        result! Input your answer: </p>
    
    <script src= "RandomNumberMaker.js">
    </script>

    </body>
</html>

This is my JavaScript:

var number = window.alert("Please Enter A Number Between One and Ten: ");

var random = Math.floor(Math.random() * 10) + 1;

if (random == number)
{
    document.write ("Your Guess Was Correct!");
    document.write(random);
    }else
    {
    document.write ("Your Guess Was Incorrect. The Correct Answer Was: " + random);
}

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

0

You can use prompt to get a user input as sort of alert type

var number = window.prompt("Please Enter A Number Between One and Ten: ");

var random = Math.floor(Math.random() * 10) + 1;

if (random == number) {
  document.write("Your Guess Was Correct! It is" + number);
  document.write(random);
} else {
  document.write("Your Guess Was Incorrect. The Correct Answer Was: " + random + " not " + number);
}
<h2> Guessing For Random Numbers! </h2>
<p> A random number between one (1) and ten (10) will be selected. Try to guess the result! Input your answer: </p>

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!