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

138
Visualizações
How would I take a variable like N and change it to a number that a user inputs?

I'm writing code that asks a user to input a number in a window prompt. When the prompt goes away, I want there to be a statement saying "Choose a number between 1 and n" with n being replaced by whatever number they input. Is that something I can do on the HTML side or is it done through JavaScript? I'm very new to this stuff. I've been searching this site all day and trying to figure this out from other posts but I haven't had any luck. Appreciate the help.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"         href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<title>Higher Lower</title>
</head>
<body>
<div class="container">
<h1>Higher - Lower</h1>

<p>Guess a number between 1 and n.</p>
let valid_input = false;
let num_range, input;
let number_guesses = [];

// validating that max input is positive
while(!valid_input) {
    input = window.prompt("Enter a positive, max value:");

    num_range = Number(input);

    if(num_range != NaN && num_range > 0) {
        valid_input = true;
         }
   }

document.getElementById('button').addEventListener('choice', do_guess)


about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Give some id to <p> tag 
for suppose - <p id="range">Guess a number between 1 and n.</p>

and add **document.getElementById("range").innerHTML = "Guess a number between 1 and " + input;** right next to **input = window.prompt("Enter a positive, max value:");**
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