Mines Calculator

by StakeDices

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Smart Gambling Edge Stake Mines Game Calculator v1.1</title>
 </head>
<body>
  <div class="post-outer">
    <div class="post">
      <div class="post-header">
              </div>
 <div>
  <h4><strong>1. Total Mines and Diamonds Limit:</strong></h4>
     The sum of mines and diamonds cannot exceed 25.
 </div>

  <div><h4>
    <p><strong>2. Minimum Value for Mines and Diamonds:</strong></p></h4>
    <p>The minimum value for mines and diamonds is 1.</p>
  </div>

  <div><h4>
    <p><strong>3. Valid Results:</strong></p></h4>
    <p>If you enter incorrect values, you will not get valid results, and you will see the same value repeated.</p>
  </div>

  <div><h4>
    <p><strong>4. Input Boxes:</strong></p></h4>
    <p>The first box is for the number of mines, and the second is for the number of diamonds.</p>
  </div>

  <div><h4>
    <p><strong>5. Winning Calculation:</strong></p></h4>
    <p>If you want to know how much you will win with a specific bet, also enter the bet amount.</p>
  </div>
  
  <hr>
  <br>

      <label for="m">Enter the number of:</label>
      <input id="m" placeholder="Mines" type="text">
      <input id="d" placeholder="Diamonds" type="text"><br>
      <br>

      <label for="bet">Bet Amount:</label>
      <input id="bet" type="text"><br>
      <br>

      <button id="calculate">Calculate</button><br>
      <hr>

      <strong>Multiplier is:</strong>
      <span id="result">-</span>x

      <strong>Win Amount is:</strong>
      <span id="win"></span><br>

      <strong>Min. Increase on Loss is:</strong>
      <span id="loss">-</span>%
      
      <strong>Winning Chance is:</strong>
      <span id="chance">-</span>%
          

</div>
</body>
</html>

CSS

body {
      font-family: 'Arial', sans-serif;
      background-color: #f5f5f5;
      color: #333;
      margin: 20px;
      padding: 20px;
    }

    h2 {
      color: #3498db;
    }

    hr {
      border: 1px solid #ddd;
    }

    b {
      font-weight: bold;
    }

    input {
      margin-bottom: 10px;
      padding: 8px;
      border: 1px solid #ddd;
      border-radius: 5px;
    }

    button {
      background-color: #00d9a6;
      color: #fff;
      padding: 10px 20px;
      border: none;
      border-radius: 5px;
      cursor: pointer;
    }

    button:hover {
      background-color: #2c3e50;
    }

    span {
      font-weight: bold;
      color: #27ae60;
    }

JavaScript

document.getElementById('calculate').onclick = function(){
                var m = parseFloat(document.getElementById('m').value),
                    d = parseFloat(document.getElementById('d').value),
                    bet = parseFloat(document.getElementById('bet').value);
                
                var n = 25, x = 25 - m;

                function factorial(number) {
                  var value = number;
                  for (var i = number; i > 1; i--)
                    value *= i - 1;
                  return value;
                };

                function combination(n, d) {
                  if (n == d) return 1;
                  return factorial(n) / (factorial(d) * factorial(n - d));
                };

                function combination(x, d) {
                  if (x == d) return 1;
                  return factorial(x) / (factorial(d) * factorial(x - d));
                };

                var first = combination(n, d);
                var second = combination(x, d);
                var result = 0.99 * (first / second);
                result = Math.round(result * 100) / 100;
                var win = bet * result;
                win = Math.round(win * 100000000) / 100000000;
                loss = 100 / (result - 1);
                loss = Math.round(loss * 100) / 100;
                chance = 99 / result;
                chance = Math.round(chance * 100000) / 100000;

                if (m + d <= 25 && d > 0 && m > 0) {
                  if (m && d) {
                    document.getElementById('result').innerHTML = result;
                    document.getElementById('loss').innerHTML = loss;
                    document.getElementById('chance').innerHTML = chance;
                    if (bet > 0.00000000999)
                      document.getElementById('win').innerHTML = win;
                  }
                }
              };