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

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

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 Report

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