如何将最小值设置为 70 以及如何阻止人们输入字母和符号。我如何将运行总计加起来?
运行总计
function CalculateTotal()
{
var intCalculateTotal = 0;
var intMinValue = 70;
var intInput;
var boolMoreNumbers = true;
var boolCorrectInput = true;
for (var intCount= 70; intCount<=15; intCount++)
{
intInput=parseInt(prompt("Please Enter a number higher than 70", ""));
if (i <=70)
{
alert ("Minimum number needs to be 70");
}
if (intInput > intMinValue)
{
intCalculateTotal = intCalculateTotal + intMinValue;
}
}
alert("The running Total is " + intCalculateTotal);
}
计算运行总计
Running Total
function CalculateTotal()
{
var intCalculateTotal = 0;
var intMinValue = 70;
var intInput;
var boolMoreNumbers = true;
var boolCorrectInput = true;
for (var intCount= 70; intCount<=15; intCount++)
{
intInput=parseInt(prompt("Please Enter a number higher than 70", ""));
if (i <=70)
{
alert ("Minimum number needs to be 70");
}
if (intInput > intMinValue)
{
intCalculateTotal = intCalculateTotal + intMinValue;
}
}
alert("The running Total is " + intCalculateTotal);
}
Calculate Running Total
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法阻止人们输入字母和符号...但您可以使用正则表达式查找它们并发出另一个警报。或者,您可以忽略它们 - 您的 parseInt 将忽略非数字并为您提供输入的数字部分,就好像它们不存在一样。
您的代码已经只添加 int 如果它 > 70,尽管您没有提醒用户这一点,因为您的代码会检查循环变量是否> > 70. 如果您想提醒用户,您需要:
You can't stop people from putting in letters and symbols... but you can look for them with a regex and put up another alert. Alternatively you can just ignore them - your parseInt will just ignore non-digits and give you the digit-part of the input as though they weren't there.
You code already only adds the int if it's > 70, though you're not alerting the user of this, because instead your code checks that the loop variable is > 70. If you'd like to alert the user, you'd need: