Created
January 29, 2019 19:58
-
-
Save chancancode/f1848c146264c75f581cf0410e94eb87 to your computer and use it in GitHub Desktop.
New Twiddle
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
import Ember from 'ember'; | |
import { task, timeout } from 'ember-concurrency'; | |
const { Controller, computed, computed: { or } } = Ember; | |
export default Controller.extend({ | |
jackpot: 1000, | |
jackpotText: computed('jackpot', function() { | |
return `$$${this.jackpot.toFixed()}`; | |
}), | |
odds: 0.001, | |
oddsText: computed('odds', function() { | |
return `1 in ${(1/this.odds).toFixed()}`; | |
}), | |
didWin: false, | |
buttonDisabled: or('didWin', 'draw.isRunning'), | |
buttonLabel: 'Try Your Luck', | |
draw: task(function *() { | |
let { jackpot, odds } = this; | |
let didWin = Math.random() < odds; | |
if (didWin) { | |
this.setProperties({ didWin }); | |
return; | |
} else { | |
odds /= 2; | |
jackpot *= 2; | |
this.setProperties({ odds, jackpot }); | |
let seconds = 30; | |
while (seconds > 0) { | |
this.set('buttonLabel', `Sorry, you didn't win :( Try again in ${seconds}s...`); | |
yield timeout(1000); | |
seconds--; | |
} | |
this.set('buttonLabel', 'Try Your Luck'); | |
} | |
}).drop(), | |
}); | |
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
{ | |
"version": "0.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3" | |
}, | |
"addons": { | |
"ember-concurrency": "0.8.19" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment