<!DOCTYPE html>
<html>
<head>
    <title>Rock Paper Scissors Online Game</title>
    <style>
        button {
            font-size: 18px;
            padding: 5px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <h1>Rock Paper Scissors</h1>
    <button onclick="play('rock')">Rock</button>
    <button onclick="play('paper')">Paper</button>
    <button onclick="play('scissors')">Scissors</button>
    <p id="result"></p>
    <script>
        function getRandomInt(min, max) {
            min = Math.ceil(min);
            max = Math.floor(max);
            return Math.floor(Math.random() * (max - min + 1)) + min;
        }
        function play(userChoice) {
            var choices = ['rock', 'paper', 'scissors'];
            var computerChoice = choices[getRandomInt(0, 2)];
            document.getElementById('result').innerHTML = 
                'Computer chose ' + computerChoice + '<br>';
<pre><code>        if (userChoice === computerChoice) {
            document.getElementById('result').innerHTML += 'Tie!';
        } else if (userChoice === 'rock' &amp;&amp; computerChoice === 'scissors') {
            document.getElementById('result').innerHTML += 'You win!';
        } else if (userChoice === 'paper' &amp;&amp; computerChoice === 'rock') {
            document.getElementById('result').innerHTML += 'You win!';
        } else if (userChoice === 'scissors' &amp;&amp; computerChoice === 'paper') {
            document.getElementById('result').innerHTML += 'You win!';
        } else {
            document.getElementById('result').innerHTML += 'You lose!';
        }
    }
&lt;/script&gt;
</code></pre>
</body>
</html>
Play Rock Paper Scissors Online - Free Game

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

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