Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda