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

212
Views
How do i make a number print on keypress on javascript

i built a website to generate random numbers, but how can i make it so if i press control it will show the number i want.

I have tried several methods but those didn't help me, i want it to print the number i want when control or enter is pressed.

It generates numbers between 1-100 randomly.

AOS.init();

// Selects elements in index.html
const display = document.querySelector('#display')
const generateButton = document.querySelector("#generate")
const minimumInput = document.querySelector('#minimum')
const maximumInput = document.querySelector('#maximum')

/**
 * Creates a random number in the given range
 * @param {*} range Difference between lowest and highest values
 */
function random(range) {

    // Returns random number
    return Math.floor(Math.random() * range)
}

/**
 * Displays a random number of the given range
 */
function randomRange() {

    // Store value of minimumInput and maximumInput into variables and converts them into integer
    const minimumValue = parseInt(minimumInput.value)
    const maximumValue = parseInt(maximumInput.value)

    // Calculates and stores random number using random()
    let randomNumber = random(maximumValue - minimumValue) + minimumValue

    // Display randomNumber to user
    display.innerHTML = randomNumber
}

// Activates function once button is clicked
generateButton.addEventListener("click", randomRange)```

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

0

you should add a keydown event for that

document.addEventListener('keydown', (e) => {...})
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!