Monday, 29 May 2023

Rock, Paper, Scissors Game using HTML & JAVASCRIPT by getcodr





 <!DOCTYPE html>
<html>
<head>
  <title>Rock, Paper, Scissors Game</title>
</head>
<body>
  <h1>Rock, Paper, Scissors Game</h1>
  <p>Make your choice:</p>
  <button onclick="playGame('rock')">Rock</button>
  <button onclick="playGame('paper')">Paper</button>
  <button onclick="playGame('scissors')">Scissors</button>
  <p id="result"></p>

  <script>
    function playGame(userChoice) {
      var choices = ["rock", "paper", "scissors"];
      var computerChoice = choices[Math.floor(Math.random() * choices.length)];
      var result = document.getElementById("result");

      result.textContent = "Your choice: " + userChoice
                           + " | Computer's choice: " + computerChoice;

      if (userChoice === computerChoice) {
        result.textContent += " | It's a tie!";
      } else if (
        (userChoice === "rock" && computerChoice === "scissors") ||
        (userChoice === "paper" && computerChoice === "rock") ||
        (userChoice === "scissors" && computerChoice === "paper")
      ) {
        result.textContent += " | You win!";
      } else {
        result.textContent += " | Computer wins!";
      }
    }
  </script>
</body>
</html>


                                MY YOUTUBE CHANNEL
                                     getcodr


No comments:

Post a Comment

This is me