JSFiddle - React, Tailwind, and code Playground

by Sean Wessell

HTML

<button id="play">
  PlayGame
</button>

<button id="results">
  getResults
</button>

<div id="output">

</div>

CSS

.number {
  width: 10%;
  float: left;
  text-align: center;
}

.number.winner {
  background: red;
  color: yellow;
}

JavaScript

var $body = $('body');
var gameCount = 0

for (ix = 1; ix < 81; ix++) {
  window['$' + ix] = 0
}

$('#play').click(function() {

  var winners = []
  for (i = 1; i < 21; i++) {
    var rando = Math.floor(Math.random() * 81)
    if ($.inArray(rando, winners) == -1) {
      window['$' + rando]++
        winners.push(rando);
    }
  }

  gameCount++;
  $('#output').html(gameCount);
})

var totalGames = 1000000

for (i2 = 1; i2 < (totalGames + 1); i2++) {
  $('#play').click();
}


$('#results').click(function() {
  $('#output').html('')
  for (x = 1; x < 81; x++) {
    $('#output').append(x + ' = ' + window['$' + x] + ' time ('+ (Math.round((window['$' + x]/totalGames)*1000)/1000) +')<br />')

  }
});