[英]Getting number from a prompt and looping
I want to create a function where I get a number from a prompt and then create a loop where the number I got is the number of time the alert() executes. 我想创建一个从提示中获取数字的函数,然后创建一个循环,其中获取的数字是alert()执行的时间。
I tried like this : 我这样尝试过:
function game() {
var i = prompt("Choose a number");
for(i; i === 0; i--) {
alert("ALERT");
}
}
game();
But after I get the prompt(), nothing happens 但是,当我得到提示()后,什么也没发生
Your for-loop condition is wrong. 您的for循环条件是错误的。 Should be i>0, not i===0.
应该是i> 0,而不是i === 0。
Or... 要么...
while(i) {
alert("ALERT");
i--;
}
Zero evaluates as false. 零评估为假。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.