有人可以请我帮忙,它是我第三天学习JS而我试图添加do while循环直到摇滚,纸张或剪刀进入提示但似乎它不起作用,试图找出它现在几个小时......有了这个代码提示总是出现无关紧要。
// a. User makes a choice
var userChoice = prompt("Do you choose ROCK, PAPER or SCISSORS?");
do {
userChoice = prompt("Do you choose ROCK, PAPER or SCISSORS?");
}
while (userChoice != "rock" && userChoice != "paper" && "scissors");
var computerChoice = Math.random();
// b. Computer makes a choice
if (computerChoice <= 0.33) {
computerChoice = "rock";
} else if (computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
var choice1 = userChoice;
var choice2 = computerChoice;
// c. A compare function will determine who wins
function compare (choice1, choice2){
if (choice1 === choice2){
alert("A tie!");
}
else if (choice1 === "rock"){
if (choice2 === "paper"){
alert("Computer chose PAPER, you LOSE!");
} else
alert("Computer chose SCISSORS, you WIN!");
}
else if (choice1 === "paper"){
if (choice2 === "scissors"){
alert("Computer chose SCISSORS, you LOSE!");
} else
alert("Computer chose ROCK, you WIN!");
}
else if (choice1 === "scissors"){
if (choice2 === "rock"){
alert ("Computer chose ROCK, you lose!");
} else
alert("Computer chose PAPER, you WIN!");
}
}
compare (userChoice, computerChoice);
console.log("You chose:", choice1, "||", "Computer chose:", choice2);
答案 0 :(得分:0)
提示,因为
pod install
始终评估为true。你可能想要
import TCPickerView
答案 1 :(得分:0)
您的代码中存在以下几个问题:
userChoice
条件<{1}}内的and
比较中缺少变量名称while
do
块内时,您不需要提示用户选择。您只需在do
块中提示用户选择。
var userChoice;
do {
userChoice = prompt("Do you choose ROCK, PAPER or SCISSORS?");
}
while (userChoice != "rock" && userChoice != "paper" && userChoice != "scissors");
var computerChoice = Math.random();
// b. Computer makes a choice
if (computerChoice <= 0.33) {
computerChoice = "rock";
} else if (computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
var choice1 = userChoice;
var choice2 = computerChoice;
// c. A compare function will determine who wins
function compare (choice1, choice2){
if (choice1 === choice2){
alert("A tie!");
}
else if (choice1 === "rock"){
if (choice2 === "paper"){
alert("Computer chose PAPER, you LOSE!");
} else
alert("Computer chose SCISSORS, you WIN!");
}
else if (choice1 === "paper"){
if (choice2 === "scissors"){
alert("Computer chose SCISSORS, you LOSE!");
} else
alert("Computer chose ROCK, you WIN!");
}
else if (choice1 === "scissors"){
if (choice2 === "rock"){
alert ("Computer chose ROCK, you lose!");
} else
alert("Computer chose PAPER, you WIN!");
}
}
compare (userChoice, computerChoice);
console.log("You chose:", choice1, "||", "Computer chose:", choice2);