gpt4 book ai didi

javascript - 代码停止循环

转载 作者:行者123 更新时间:2023-12-03 06:02:43 24 4
gpt4 key购买 nike

我的代码无法正常工作。它不会继续循环。它只是表明你的值(value)是低还是高,然后就到此为止。为什么不继续循环?

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

最佳答案

当值较高或较低时,您使用return false;。将其替换为继续;

关于javascript - 代码停止循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39687664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com