0
我的代碼無法正常工作。它不是繼續循環。它只是表明你的價值低或高,並在那裏停止。爲什麼它不保持循環?代碼停止循環
var target;
var count = 0;
var play;
var game;
function do_this() {
var choose = (Math.floor(Math.random() * 100));
target = choose + 1;
while (true) {
play = prompt("I am thinking of a no. between 1 and 100\n\n" + "enter the no.");
game = parseInt(play);
count = count + 1;
if (isNaN(game)) {
alert("Please enter integer value");
return false;
}
if ((game < 1) || (game > 100)) {
alert("Please enter the value between 1 and 100");
return false;
}
if (game < choose) {
alert("enter higher value");
return false;
}
if (game > choose) {
alert("enter lower value");
return false;
}
alert("You are correct\n\n" + "you took" + count + "to guess the game");
return true;
}
}
do_this()
請格式化爲可讀 –
可能的重複[Does return stop a loop?](http://stackoverflow.com/questions/11714503/does-return-stop-a-loop) – showdev