0
這是我的第一款遊戲和Rock Paper Scissors遊戲的代碼,其中CodeAcademy進行了一些調整。我一直困住了兩個小時,試圖弄清楚爲什麼它會一直持續下去。總是一個TIE! Rock Paper Scissors遊戲
這是我的HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Rock Paper Scissors</title>
</head>
<body>
<form>
Rock
<input type="checkbox" id="rock">
Paper
<input type="checkbox" id="paper">
Scissors
<input type="checkbox" id="scissors">
<button onclick="startGame()">Start<button>
</form>
<script src="userInt.js"></script>
</body>
</html>
JavaScript代碼:
function userChoice(){
var rock = document.getElementById("rock").checked;
var scissors = document.getElementById("scissors").checked;
var paper = document.getElementById("paper").checked;
}
function computerChoice(){
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
}
function compare(userChoice, computerChoice){
if (userChoice === computerChoice){
return "The result is a tie!";
}
if (userChoice ==="rock"){
if(computerChoice ==="scissors"){
return "rock wins";
}else{
return "paper wins";
}
}
if(userChoice ==="paper"){
if (computerChoice ==="scissors"){
return "paper wins"
}else{
return "scissors wins"
}
}
if(userChoice ==="scissors"){
if (computerChoice ==="rock"){
return "rock wins"
}else{
return "scissors wins"
}
}
}
function startGame(){
var getUserChoice = userChoice();
var getComputerChoice = computerChoice();
var endGame = compare(getUserChoice, getComputerChoice);
alert(endGame)
}
感謝您的支持!