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

414
Visualizações
Why does Number.isInteger() return false even when I prompt in integer values?
do {
    var y = prompt("Enter a positive integer from 1 to 26");
    var int = Number.isInteger(y);
    var x = parseInt(y);
    window.alert(int);
} while (x > 26 || x < 1 || int == false)

this is the code I wrote but it still keeps alerting int as false whenever I enter an integer on my browser.

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

0

Number.isInteger() is used to tell if a value that's already a number is an integer.

I.e.

Number.isInteger(5) == true
Number.isInteger(5.1) == false

Passing a string into Number.isInteger() will always return false.

about 4 years ago · Juan Pablo Isaza Relatório

0

Because prompt() always returns a string. It is up to you to make it integer:

let y = prompt("Enter a positive integer from 1 to 26");
y = parseInt(y);
if (y === NaN) {
    alert('Please enter a number');
} else {
    while(x > 26 || x < 1 || int == false)
}
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