Play Rock Paper Scissors Online - Fun Game
<html>
<head>
<title>Rock Paper Scissors Game</title>
</head>
<body>
<h1>Choose Your Weapon</h1>
<form action="">
<input type="radio" name="weapon" value="rock">Rock<br>
<input type="radio" name="weapon" value="paper">Paper<br>
<input type="radio" name="weapon" value="scissors">Scissors<br>
<input type="submit" value="Submit">
</form>
<script>
let player = document.querySelector('input[name="weapon"]:checked').value;
let computer = Math.random();
if (computer < 0.34) {
computer = 'rock';
} else if(computer <= 0.67) {
computer = 'paper';
} else {
computer = 'scissors';
}
let compare = function(choice1, choice2) {
if(choice1 === choice2) {
return 'The result is a tie!';
}
if(choice1 === 'rock') {
if(choice2 === 'scissors') {
return 'rock wins';
} else {
return 'paper wins';
}
}
if(choice1 === 'paper') {
if(choice2 === 'rock') {
return 'paper wins';
} else {
if(choice2 === 'scissors') {
return 'scissors wins';
}
}
}
if(choice1 === 'scissors') {
if(choice2 === 'rock') {
return 'rock wins';
} else {
if(choice2 === 'paper') {
return 'scissors wins';
}
}
}
};
compare(player, computer);
</script>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/lmnZ 著作权归作者所有。请勿转载和采集!