Skip to content

Instantly share code, notes, and snippets.

@danieluhl
Created January 13, 2016 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieluhl/8710c54c9814bc8dc3f8 to your computer and use it in GitHub Desktop.
Save danieluhl/8710c54c9814bc8dc3f8 to your computer and use it in GitHub Desktop.
HTML version of luck tester
<input id="button" type="button" value="WHAT'S MY LUCK!?!" onclick="return window.run()" />
<h1 id="results"></h1>
<script type="text/javascript">
var count = 0;
var result = '';
window.run = function() {
console.log('running');
var rand = Math.floor((Math.random() * 292000000)) + 1;
var check = 0;
while(true) {
check = Math.floor((Math.random() * 292000000)) + 1;
if(check === rand) {
break;
}
rand = Math.floor((Math.random() * 292000000)) + 1;
count++;
}
result = 'You spent ' + (count * 2).toLocaleString('en-US', {
style: 'currency',
currency: 'USD'
});
result = result + '<br />Your luck is 1 in ' + count
result = result + '<br />Given the 1.5B payout you made ' + (1500000000 - (count * 2)).toLocaleString('en-US', {
style: 'currency',
currency: 'USD'
});
document.getElementById('results').innerHTML=result;
document.getElementById('button').value='TRY AGAIN?';
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment