我正在制作一个筷子游戏,这是我正在制作的第一个应用程序(对于javascript来说真的很新)我希望它在达到某个点时重新启动,直到敌人或你的手都有5根筷子。这是我的代码:
var nocLeft = 1;
var nocRight = 1;
var handChoice = prompt("You now have " + nocLeft + " chopstick(s) on your left hand, and " + nocRight+ " chopstick(s) on your right hand, which hand do you want to use?").toLowerCase();
if (handChoice === right){
var ehc = prompt("Which hand are you attacking? The enemy's left hand has " + noceLeft + ", and their right hand has " + noceRight + " chopsticks.").toLowerCase();
switch(ehc) {
case 'right':
console.log("You chose the right hand!");
break;
case 'left':
console.log("You chose the right hand!");
break;
default:
console.log("please answer with 'left' or 'right', thanks!");
}
}
else if (handChoice === left){
var ehc = prompt("Which hand are you attacking? The enemy's left hand has " + noceLeft + ", and their right hand has " + noceRight + " chopsticks.").toLowerCase;
}
else {
}
答案 0 :(得分:0)
这是一种方法:
var exit = false;
while (exit != true) {
// Your code
// Use the next line to get out of the loop
// exit = true;
}
上述方法将在到达结束后退出循环。如果您想立即退出,可以使用break
。