Play Rock Paper Scissors Online - Fun & Simple Game
<html>
<head>
<title>Rock Paper Scissors Online - Free Game</title>
</head>
<body>
<h1>Rock Paper Scissors!</h1>
<h2>Choose one of the following:</h2>
<ul>
<li><button type="button" onclick="chooseRock()">Rock</button></li>
<li><button type="button" onclick="choosePaper()">Paper</button></li>
<li><button type="button" onclick="chooseScissors()">Scissors</button></li>
</ul>
<p id="result"></p>
<script>
function chooseRock() {
let computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = 'rock';
} else if(computerChoice <= 0.67) {
computerChoice = 'paper';
} else {
computerChoice = 'scissors';
}
document.getElementById("result").innerHTML =
'Computer chose: ' + computerChoice +
'. You chose rock. It's a tie!';
}
function choosePaper() {
let computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = 'rock';
} else if(computerChoice <= 0.67) {
computerChoice = 'paper';
} else {
computerChoice = 'scissors';
}
document.getElementById("result").innerHTML =
'Computer chose: ' + computerChoice +
'. You chose paper. You win!';
}
function chooseScissors() {
let computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = 'rock';
} else if(computerChoice <= 0.67) {
computerChoice = 'paper';
} else {
computerChoice = 'scissors';
}
document.getElementById("result").innerHTML =
'Computer chose: ' + computerChoice +
'. You chose scissors. You lose!';
}
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lmqQ 著作权归作者所有。请勿转载和采集!