简体   繁体   中英

A simple exercise but I cannot find the mistake the function doesn't work

Can't find the problem function doesn't work. I want to to be sure that ps input is a number if not give alert. Without the function it works I suppose I have in the function something missing

You can use the isNaN() function to check weather the entered prompt is number or not.

 function myFunction() { var ps = prompt("Bitte geben sie ihre PS an.", " "); while(isNaN(ps)) { alert('Enter a number') ps = prompt("Bitte geben sie ihre PS an.", " "); } var age = prompt("Bitte geben sie ihr Alter an", " "); while(isNaN(age)) { alert('Enter a number') age = prompt("Bitte geben sie ihr Alter an", " "); } var austria = + ps + 100 / + age + 50; var result = alert("Sie zahlen pro Monat:" + (Math.floor(austria))); if(ps < 100) { alert("Bitte geben sie eine Zahl ein."); } } myFunction();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM