<!DOCTYPE html>
<html>
<head>
<title>Rock, Paper, Scissors</title>
</head>
<body>
<h1>Let's Play Rock, Paper, Scissors!</h1>
<p>Choose one of the following:</p>
<p><button type="button" onclick="rock()">Rock</button>
<button type="button" onclick="paper()">Paper</button>
<button type="button" onclick="scissors()">Scissors</button></p>
<p>You chose: <span id="choice"></span></p>
<p>Computer chose: <span id="computerChoice"></span></p>
<p id="result"></p>
<script>
    function computerChoice() {
        const choices = ['rock', 'paper', 'scissors'];
        return choices[Math.floor(Math.random() * choices.length)];
    }
    
    function playerChoice(choice) {
        document.getElementById('choice').innerHTML = choice;
        document.getElementById('computerChoice').innerHTML = computerChoice();
    }
    
    function rock() {
        playerChoice('Rock');
    }
    
    function paper() {
        playerChoice('Paper');
    }
    
    function scissors() {
        playerChoice('Scissors');
    }
</script>
</body>
</html>
Play Rock Paper Scissors: Simple HTML Game

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

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