Rock Paper Scissors Game

This is a simple game of Rock Paper Scissors that you can play online.

Instructions

  1. Choose either rock, paper, or scissors by clicking on the corresponding button.
  2. The computer will randomly choose its move.
  3. The winner will be displayed on the screen.

Game Board

Result

Script

<script>
function play(userChoice) {
  var choices = ['rock', 'paper', 'scissors'];
  var computerChoice = choices[Math.floor(Math.random() * 3)];
  var result;

  if (userChoice === 'rock' && computerChoice === 'scissors' ||
      userChoice === 'paper' && computerChoice === 'rock' ||
      userChoice === 'scissors' && computerChoice === 'paper') {
    result = 'You Win!';
  } else if (userChoice === computerChoice) {
    result = 'It's a tie!';
  } else {
    result = 'You Lose!';
  }

  document.getElementById('result').innerHTML = `You chose ${userChoice}, the computer chose ${computerChoice}. ${result}`;
}
</script>

原文地址: https://www.cveoy.top/t/topic/lmq8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录