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

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

0

you should add a keydown event for that

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