Toss Coin Game Code

 Toss Coin Game Free Code Download. 

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Toss Coin Game</title>

  <style>

    body {

      font-family: Arial, sans-serif;

      margin: 0;

      padding: 0;

      display: flex;

      justify-content: center;

      align-items: center;

      height: 100vh;

      background: linear-gradient(135deg, #ff9a9e, #fad0c4);

      color: #333;

    }

    .container {

      text-align: center;

      background: #fff;

      border-radius: 10px;

      box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);

      padding: 20px;

      width: 90%;

      max-width: 400px;

    }

    h1 {

      margin-bottom: 20px;

      font-size: 24px;

      color: #4a4a4a;

    }

    .coin {

      font-size: 60px;

      margin: 20px 0;

      display: inline-block;

      animation: flip 1s;

    }

    @keyframes flip {

      0%, 100% {

        transform: rotateY(0deg);

      }

      50% {

        transform: rotateY(180deg);

      }

    }

    .button {

      background: #6a11cb;

      background: linear-gradient(to right, #6a11cb, #2575fc);

      border: none;

      color: white;

      padding: 10px 20px;

      font-size: 16px;

      cursor: pointer;

      border-radius: 5px;

      margin-top: 10px;

      transition: background 0.3s;

    }

    .button:hover {

      background: #3b8dfe;

    }

    .history {

      margin-top: 20px;

      font-size: 14px;

    }

    .history ul {

      list-style-type: none;

      padding: 0;

    }

    .history li {

      margin: 5px 0;

    }

  </style>

</head>

<body>

  <div class="container">

    <h1>Toss Coin Game</h1>

    <div id="coin" class="coin">🪙</div>

    <button class="button" onclick="tossCoin()">Toss Coin</button>

    <div class="history">

      <h2>History</h2>

      <ul id="historyList"></ul>

    </div>

  </div>


  <script>

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

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


    function tossCoin() {

      // Randomly choose Heads or Tails

      const isHeads = Math.random() < 0.5;

      const result = isHeads ? 'Heads' : 'Tails';


      // Update the coin emoji

      coin.textContent = isHeads ? '🙂' : '🙃';

      coin.style.animation = 'none';


      // Trigger the animation

      setTimeout(() => {

        coin.style.animation = 'flip 1s';

      }, 10);


      // Update history

      const listItem = document.createElement('li');

      listItem.textContent = result;

      historyList.insertBefore(listItem, historyList.firstChild);

    }

  </script>

</body>

</html>


Admin

A Software Engineer, Social Media Marketing Expert, writer,

Post a Comment

Previous Post Next Post