Last active
December 19, 2016 09:42
-
-
Save voltrevo/dbb1eaaf112ed33ee3d2f02ab21c0665 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
window.addEventListener('load', () => { | |
const txt = document.createElement('span'); | |
document.body.appendChild(txt); | |
const btn = document.createElement('button'); | |
document.body.appendChild(btn); | |
let money = 100; | |
let target = 101; | |
let bet = () => Math.min(money, target - money); | |
btn.textContent = 'Gamble'; | |
let render = () => { | |
txt.textContent = `Money: $${money}, Target: $${target}, Bet: $${bet()} `; | |
}; | |
render(); | |
btn.addEventListener('click', () => { | |
let mul = 2 * Math.round(Math.random()) - 1; | |
money += mul * bet(); | |
if (money === target) { | |
target += 1; | |
} | |
render(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment