Rock Paper Scissors Game: Play Now!
<!DOCTYPE html>
<html>
<head>
<title>Rock Paper Scissors</title>
<script>
function runGame(){
let userChoice = prompt('Rock, Paper, Scissors?');
let computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = 'Rock';
} else if(computerChoice <= 0.67) {
computerChoice = 'Paper';
} else {
computerChoice = 'Scissors';
}
console.log('Computer: ' + computerChoice);
if (userChoice === computerChoice){
alert('It's a Tie!');
}
else if (userChoice === 'Rock'){
if (computerChoice === 'Paper'){
alert('Computer Wins!');
}
else{
alert('You Win!');
}
}
else if (userChoice === 'Paper'){
if (computerChoice === 'Scissors'){
alert('Computer Wins!');
}
else{
alert('You Win!');
}
}
else if (userChoice === 'Scissors'){
if (computerChoice === 'Rock'){
alert('Computer Wins!');
}
else{
alert('You Win!');
}
}
else{
alert('Invalid Choice!');
}
}
</script>
</head>
<body>
<button onclick="runGame()">Play Rock Paper Scissors</button>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lmlC 著作权归作者所有。请勿转载和采集!