简体   繁体   English

一个简单的练习,但我找不到功能不起作用的错误

[英]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.如果不发出警报,我想确保 ps 输入是一个数字。 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.您可以使用isNaN()函数来检查输入的提示是否为数字的天气。

 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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