Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda