• Join CraxPro and earn real money through our Credit Rewards System. Participate and redeem credits for Bitcoin/USDT. Start earning today!
    Read the detailed thread here

Dice game html source code

Currently reading:
 Dice game html source code

allwebtestbb

Member
LV
0
Joined
Aug 6, 2024
Threads
5
Likes
0
Awards
1
Credits
330©
Cash
0$
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dice Game</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            height: 100vh;
            font-family: Arial, sans-serif;
            background-color: #e0f7fa;
        }
        h1 {
            color: #333;
        }
        .game-container {
            background: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            text-align: center;
        }
        .dice {
            display: flex;
            justify-content: space-around;
            margin: 20px 0;
        }
        .dice img {
            width: 100px;
            height: 100px;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            color: #fff;
            background-color: #007bff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
        .message {
            margin-top: 10px;
            font-size: 18px;
            color: #555;
        }
    </style>
</head>
<body>

<div class="game-container">
    <h1>Dice Game</h1>
    <div class="dice">
        <div>
            <p>Player 1</p>
            <img src="https://via.placeholder.com/100?text=?" id="dice1" alt="Dice 1">
        </div>
        <div>
            <p>Player 2</p>
            <img src="https://via.placeholder.com/100?text=?" id="dice2" alt="Dice 2">
        </div>
    </div>
    <button onclick="rollDice()">Roll Dice</button>
    <p class="message" id="message"></p>
</div>

<script>
    // Function to roll the dice for both players
    function rollDice() {
        const dice1 = Math.floor(Math.random() * 6) + 1; // Random number between 1 and 6
        const dice2 = Math.floor(Math.random() * 6) + 1;

        // Update the dice images based on the rolled numbers
        document.getElementById('dice1').src = `https://via.placeholder.com/100?text=${dice1}`;
        document.getElementById('dice2').src = `https://via.placeholder.com/100?text=${dice2}`;

        const message = document.getElementById('message');

        // Determine the winner based on the rolled numbers
        if (dice1 > dice2) {
            message.textContent = 'Player 1 Wins!';
            message.style.color = 'green';
        } else if (dice1 < dice2) {
            message.textContent = 'Player 2 Wins!';
            message.style.color = 'green';
        } else {
            message.textContent = 'It\'s a Draw!';
            message.style.color = 'orange';
        }
    }
</script>

</body>
</html>
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Top Bottom