<html>
    <head>
        <title>Rock Paper Scissors Game</title>
    </head>
    <body>
        <h1>Rock Paper Scissors</h1>
        <h3>Choose your move:</h3>
        <div id="choice-buttons">
            <button onclick="playerMove('rock')">Rock</button>
            <button onclick="playerMove('paper')">Paper</button>
            <button onclick="playerMove('scissors')">Scissors</button>
        </div>
        <p id="result"></p>
        <script>
            let playerChoice;
            const choices = ['rock', 'paper', 'scissors'];
            let computerChoice = choices[Math.floor(Math.random() * choices.length)];
            const result = document.getElementById('result');
<pre><code>        function playerMove(choice) {
            playerChoice = choice;

            // Compare choices and determine winner
            if (playerChoice === computerChoice) {
                result.textContent = 'It's a tie!';
            } else if (playerChoice === 'rock') {
                if (computerChoice === 'paper') {
                    result.textContent = 'Computer wins!';
                } else {
                    result.textContent = 'You win!';
                }
            } else if (playerChoice === 'paper') {
                if (computerChoice === 'rock') {
                    result.textContent = 'You win!';
                } else {
                    result.textContent = 'Computer wins!';
                }
            } else if (playerChoice === 'scissors') {
                if (computerChoice === 'rock') {
                    result.textContent = 'Computer wins!';
                } else {
                    result.textContent = 'You win!';
                }
            }
        }
    &lt;/script&gt;
&lt;/body&gt;
</code></pre>
</html>
Play Rock Paper Scissors Online - Free Game

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

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