<script>
function Play() {
var guesses = 1
var number = 0
var points = 0
var cp = 0
var level = " "
var x = 0
while (level != "a" || "A" || "b" || "B" || "c" || "C" || "d" || "D"){
level = prompt("Select Your Difficulty");
if (level == "a" || "A" || "b" || "B" || "c" || "C" || "d" || "D") {
if (level == "a" || level == "A") {
x = 30;
}
else if (level == "b" || level == "B") {
x = 50;
}
else if (level == "c" || level == "C") {
x = 70;
}
else if (level == "d" || level == "D") {
x = 100;
}
}
else if (level != "a" || "A" || "b" || "B" || "c" || "C" || "d" || "D") {
if (level == null) {
return;
}
else {
alert("You Went Sphagetti On Your Keyboard And Missed");
}
}
}
var answer = Math.floor(Math.random() * x) + 1;
number = prompt("What Is Your First Guess?");
if (number == null) {
return;
}
//The Beginning Of The While Loop
while (guesses <= 4) {
//Give The User A Point And Restart The Guesses
//Generate A New Number For Them To Guess
if (number == answer) {
alert("You Guessed Correctly! You Get One Point!");
alert("The Number Will Now Change, But Will Still Be Within 1-30");
guesses = 1;
points = points + 1;
answer = Math.floor(Math.random() * x) + 1;
number = prompt("What Is Your Guess For The New Number?");
if (number == null){
return;
}
//If The Number The User Guessed Equals The Answer
//Go Back To The Start Of The Loop
else if (number == answer) {
continue;
}
}
if (number < answer) {
alert("Wrong! The Number Is To Low! NACHO CHEESE");
}
else if (number > answer) {
alert("Wrong! The Number Is To High! YOU ARE SHELLFISH!");
}
number = prompt("You've Made " + guesses + " Guess(es)");
if (number == null) {
return;
}
if (number == answer) {
continue;
}
else if (number != answer) {
guesses = guesses + 1;
}
}
//If The User Gets Wrong On All 5 Guesses
//Tell Them They Lost And Give Them The Answer
//Display Their Total Points
alert("You Have Guessed Incorrectly 5 Times. The Number Was " + answer);
cp = points.toString();
document.getElementById("points").innerHTML= "Point Streak: " + cp;
}
</script>-
您好,我想知道为什么我的第一个while循环中的条件似乎无法正常工作。当我输入一个应该突破循环的字母,因为条件是它不等于这些字母之一时,它最终会再次要求我(“选择你的难度”)。之前它还给了我“你的键盘上的意大利面并且错过了”)当我输入一封应该突破循环的信件时...如果我没有弄错,如果在那里甚至不应该进入其他如果我输入其中一个字母对吗?请指导我出错的地方。