var target=10;
var totalGuess=0;
var input = window.prompt('Enter a number between 1 and 100: ');
var guess = parseInt(input);
do
{
totalGuess++;
if (guess < target)
{
window.prompt("Too low! Guess Again!");
}
if (guess > target)
{
window.prompt("Too High! Guess Again!");
}
if (guess == target)
{
alert("Thats right! It took you " +totalGuess +" tries to get it right!");
break;
}
} while (guess != target );
我正在尝试检查用户输入的数字是高还是低,但该程序仅检查一个语句然后停止。