问题描述
我如何使获胜者的代码打印结果和控制台的计数器? 代码的顶部现在可以正常运行。我当前的挑战是代码不会通过if / else条件,并且不会打印到控制台/代码的条件部分似乎没有运行。 我已经尝试过==和===,但没有一个起作用。我错过了什么吗?
//get computer choices
comChoices = ["rock","paper","scissors"];
function playRound() {
//get user input
userInput = prompt("please enter rock,paper or scissors");
//verify its in lowercase
userInput = userInput.toLowerCase();
if (
userInput === "rock" ||
userInput === "paper" ||
userInput === "scissors"
) {
function comrand() {
// function selects a random computer choice
randomChoice = comChoices[Math.floor(Math.random() *
comChoices.length)];
return randomChoice;
}
window.alert(comrand());
} else {
// veirfy user input
window.alert("please enter rock,paper or scissors or check your
spelling");
playRound();
}
}
//initialize count default
userWin = 0;
comWin = 0;
draw = 0;
//conditionals to determine winners
if (userInput == "rock" && randomChoice == "scissors"){
userWin++;
console.log("You win!!! (rock crushes scissors)");
} else if(userInput == "scissors" && randomChoice =="rock"){
comWin++;
console.log("Computer wins!!!(rock crushes scissors)");
} else if(userInput == "scissors" && randomChoice == "paper"){
userWin++;
console.log("You win!!! (Scissors cuts paper)");
} else if(userInput == "paper" && randomChoice == "scissors"){
comWin++;
console.log("Computer win!s!! (Scissors cuts paper)");
} else if(userInput == "paper" && randomChoice == "rock"){
userWin++;
console.log("You win!!! (paper covers rock)");
} else if(userInput == "rock" && randomChoice == "paper"){
comWin++;
console.log("Computer win!s!! (paper covers rock)");
} else {
draw++;
console.log("game is a draw");
}
if (userWin === 5){ //
conditions to determines the overall winner
console.log("User wins the game");
} else if (comWin === 5){
console.log("computer wins the game");
} else {
console.log("the game is a draw");
}
playRound();
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)