我如何运行我的石头剪刀布游戏?



我刚接触到JavaScript,我写了一个简单的石头剪子布游戏,但我无法让它运行。

var userChoice = prompt("Rock, Paper, or Scissors?")
var computerChoice = math.random()
if (computerChoice < 0.33) {
computerChoice = "Rock"
} else if (computerChoice < 0.66) {
computerChoice = "Paper"
} else {
computerChoice = "Scissors"
};
var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return "Tie, no one wins!"
}
};
if (userChoice === "Rock") {
if (computerChoice === "Scissors") {
return "You win!"
} else if (computerChoice === "Paper") {
return "You lose!"
}
};
if (userChoice === "Paper") {
if (computerChoice === "Rock") {
return "You win!"
} else if (computerChoice === "Scissors") {
return "You Lose!"
}
};
if (userChoice === "Scissors") {
if (computerChoice === "Paper") {
return "You win!"
} else if (computerChoice === "Rock") {
return "You Lose!"
}
};
console.log("Your choice was: " + userChoice);
console.log("The computer chose: " + computerChoice);
compare(userchoice, computerChoice);

这是我写的代码。我还没能解决它,看看它是否有效,但我需要一个地方来运行它。请帮助! !

您可以创建一个html文档,然后将javascript代码嵌入其中。在这里了解更多信息:https://www.javatpoint.com/how-to-call-javascript-function-in-html#:~:text=To%20include%20our%20JavaScript%20file,file%20where%20it%20is%20stored.

最新更新