Play Rock Paper Scissors Online - Simple HTML Game

Rock, Paper, Scissors

Choose one and click the button to play

<script>
  function playRock() {
    var userChoice = 'rock';
    var computerChoice = Math.random();

    if (computerChoice < 0.34) {
      computerChoice = 'rock';
    } else if(computerChoice <= 0.67) {
      computerChoice = 'paper';
    } else {
      computerChoice = 'scissors';
    }

    if (userChoice === computerChoice) {
      document.getElementById('result').innerHTML = 'It's a tie!';
    } else if (userChoice === 'rock') {
      if (computerChoice === 'scissors') {
        document.getElementById('result').innerHTML = 'You win!';
      } else {
        document.getElementById('result').innerHTML = 'Computer wins!';
      }
    } else if (userChoice === 'paper') {
      if (computerChoice === 'rock') {
        document.getElementById('result').innerHTML = 'You win!';
      } else {
        document.getElementById('result').innerHTML = 'Computer wins!';
      }
    } else if (userChoice === 'scissors') {
      if (computerChoice === 'rock') {
        document.getElementById('result').innerHTML = 'Computer wins!';
      } else {
        document.getElementById('result').innerHTML = 'You win!';
      }
    }
  }
  function playPaper() {
    var userChoice = 'paper';
    var computerChoice = Math.random();

    if (computerChoice < 0.34) {
      computerChoice = 'rock';
    } else if(computerChoice <= 0.67) {
      computerChoice = 'paper';
    } else {
      computerChoice = 'scissors';
    }

    if (userChoice === computerChoice) {
      document.getElementById('result').innerHTML = 'It's a tie!';
    } else if (userChoice === 'rock') {
      if (computerChoice === 'scissors') {
        document.getElementById('result').innerHTML = 'You win!';
      } else {
        document.getElementById('result').innerHTML = 'Computer wins!';
      }
    } else if (userChoice === 'paper') {
      if (computerChoice === 'rock') {
        document.getElementById('result').innerHTML = 'You win!';
      } else {
        document.getElementById('result').innerHTML = 'Computer wins!';
      }
    } else if (userChoice === 'scissors') {
      if (computerChoice === 'rock') {
        document.getElementById('result').innerHTML = 'Computer wins!';
      } else {
        document.getElementById('result').innerHTML = 'You win!';
      }
    }
  }
  function playScissors() {
    var userChoice = 'scissors';
    var computerChoice = Math.random();

    if (computerChoice < 0.34) {
      computerChoice = 'rock';
    } else if(computerChoice <= 0.67) {
      computerChoice = 'paper';
    } else {
      computerChoice = 'scissors';
    }

    if (userChoice === computerChoice) {
      document.getElementById('result').innerHTML = 'It's a tie!';
    } else if (userChoice === 'rock') {
      if (computerChoice === 'scissors') {
        document.getElementById('result').innerHTML = 'You win!';
      } else {
        document.getElementById('result').innerHTML = 'Computer wins!';
      }
    } else if (userChoice === 'paper') {
      if (computerChoice === 'rock') {
        document.getElementById('result').innerHTML = 'You win!';
      } else {
        document.getElementById('result').innerHTML = 'Computer wins!';
      }
    } else if (userChoice === 'scissors') {
      if (computerChoice === 'rock') {
        document.getElementById('result').innerHTML = 'Computer wins!';
      } else {
        document.getElementById('result').innerHTML = 'You win!';
      }
    }
  }
</script>
Play Rock Paper Scissors Online - Simple HTML Game

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

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