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

126
Views
How to escape a prompt with while loop with isNaN in JavaScript?

So my while loop with isNaN doesn't work when I type in number in the prompt Here is my code below...

var userSalary = prompt("Please type your salary!")

while(isNaN(userSalary)){
    prompt("Please type number!")
}
alert("Good!") 

Although I input a number, it won't let me escape from the loop...

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

0

You need to reassign userSalary inside of the loop, so the value gets refreshed:

var userSalary = prompt("Please type your salary!")

while(isNaN(userSalary)){
    userSalary = prompt("Please type number!")
}
alert("Good!")

about 4 years ago · Juan Pablo Isaza Report

0

You could combine the statements, and also try a do..while loop

var userSalary = prompt('Please type your salary!')
while (isNaN(userSalary = prompt('Please type number!'))) {}
alert('Good!')

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!