0

I am taking introductory JavaScript course, and I learned about isNaN function. I wrote a simple program where JS repeat prompt method unless user type number in the prompt. I don't know why my code doesn't work as I expected. If you input on the prompt twice, the program automatically escapes while loop.

<script>
    
     var userSalary = prompt("Hi, type a number!");

    
    while(isNaN(userSalary)){
        parseFloat(prompt(userSalary+ " is not number..."));
        userSalary.reset()
    }
    
    alert("Thank you!");
    
        
</script>
Pran Sukh
  • 207
  • 4
  • 12
user11838329
  • 51
  • 1
  • 7

1 Answers1

1

You aren't setting the value of userSalary in the loop:

var userSalary = prompt("Hi, type a number!");

while(isNaN(userSalary)){
    userSalary = parseFloat(prompt(userSalary + " is not number..."));
}
alert("Thank you!");
Rojo
  • 2,749
  • 1
  • 13
  • 34