Homegamescode Rock, Paper, Scissors Game HTML CSS & Js Source Code By Mr Secret February 04, 2024 Rock, Paper, Scissors Game HTML CSS & Js Source Code TEXT Copy Download <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> body { font-family: 'Arial', sans-serif; background-color: #f4f4f4; text-align: center; } .container { max-width: 600px; margin: 50px auto; } h1 { color: #333; } .game { display: flex; justify-content: space-around; margin-top: 20px; } .choice { background-color: #3498db; color: #fff; padding: 10px 20px; font-size: 16px; border: none; border-radius: 5px; cursor: pointer; } .choice:hover { background-color: #2980b9; } #result { margin-top: 20px; font-size: 18px; } </style> <title>Rock, Paper, Scissors Game</title> </head> <body> <div class="container"> <h1>Rock, Paper, Scissors</h1> <div class="game"> <button class="choice" onclick="playGame('rock')">Rock</button> <button class="choice" onclick="playGame('paper')">Paper</button> <button class="choice" onclick="playGame('scissors')">Scissors</button> </div> <div id="result"></div> </div> <script> function playGame(playerChoice) { var choices = ["rock", "paper", "scissors"]; var computerChoice = choices[Math.floor(Math.random() * choices.length)]; var result = ""; if (playerChoice === computerChoice) { result = "It's a tie!"; } else if ( (playerChoice === "rock" && computerChoice === "scissors") || (playerChoice === "paper" && computerChoice === "rock") || (playerChoice === "scissors" && computerChoice === "paper") ) { result = "You win!"; } else { result = "You lose!"; } document.getElementById("result").innerText = `Your choice: ${playerChoice} | Computer's choice: ${computerChoice} | Result: ${result}`; } </script> </body> </html> Tags: gamescode Facebook Twitter