我是JavaScript的新手.我刚刚开始学习它,我决定制作一个"Rock,Paper,Scissors,Lizard,Spock"游戏.这是代码:
var userChoice = prompt("Do you choose rock, paper, scissors, lizard, or spock?")
var computerChoice = Math.random();
if (computerChoice < 0.2) {
computerChoice = "rock";
} else if (computerChoice <= 0.4) {
computerChoice = "paper";
} else if (computerChoice <= 0.6) {
computerChoice = "scissors";
} else if (computerChoice <= 0.8) {
computerChoice = "lizard";
} else {
computerChoice = "spock";
}
alert("The computer chose " + computerChoice);
var compare = function(choice1, choice2){
if (choice1 === choice2) {
alert("And... It's …Run Code Online (Sandbox Code Playgroud) javascript ×1