我在下面的代码中遇到了一些麻烦,基本上我只是在练习循环并考虑制作一个小游戏来刷新......但是我有点难为为什么 while 循环允许通过一个条目像“ cat" 或 "hgh" 例如,因此在最后发出警报说一堆乱码....
var playerWeapon = prompt("Before you go to slay the Dragon, please choose your weapon from the following... \n\n1.) Sword \n2.) Crossbow\n3.) Dagger").toLowerCase();
while( (playerWeapon == '' ) && (playerWeapon != 'sword' || playerWeapon != 'dagger' || playerWeapon != 'crossbow') ){
alert("We need you to pick a weapon...");
var playerWeapon = prompt("Sorry, you need to chose a valid weapon...what will it be? \n\n1.) Sword \n2.) Crossbow\n3.) Dagger").toLowerCase();
}
var weaponStrength = '';
if(playerWeapon == "sword"){
var weaponStrength = 10;
}
if(playerWeapon == "dagger"){
var weaponStrength = 7;
}
if(playerWeapon == "crossbow"){
var weaponStrength = 4;
}
alert("Excellent, the " + playerWeapon + " is a fine choice and your weapon is " + weaponStrength + " strong...now lets go!");