如何将我的摇滚,纸张,剪刀游戏嵌入到按钮中?将JavaScript嵌入按钮
<!DOCTYPE html>
<html>
<button onclick="rockPaperScissors()">Click me</button>
<script type="text/javascript">
var rockPaperScissors(
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
var compare = function(choice1, choice2) {
if (choice1 === choice2) {
confirm("The result is a tie!";)
}
else if(choice1 === "rock") {
if (choice2 === "scissors") {
confirm("rock wins";)
}
else {
confirm("paper wins";)
}
}
//second one
else if(choice1 === "paper") {
if (choice2 === "rock") {
confirm("paper wins";)
}
else {
confirm("scissors wins";)
}
}
//third one
else if(choice1 === "scissors") {
if (choice2 === "rock") {
confirm("rock wins";)
}
else {
confirm("scissors wins";)
}
}
};
)
</script>
</html>
你没有在'var rockPaperScissors('? – jediz