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

131
Views
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 answers
Answer question

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 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!