Created
July 3, 2016 18:20
-
-
Save mrandri19/eabd1062c164f08dde509052eea80573 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'; | |
const frequency = 1000; | |
const potGoal = 20; | |
const timeAfterPotGoal = 10*1000; | |
const Pot = function() { | |
return { | |
participants: [], | |
value: 20, | |
timeoutStarted: false, | |
timeout: null, | |
isClosed: false | |
}; | |
}; | |
let state = { | |
potNumber: 0, | |
pot: new Pot() | |
}; | |
function editState() { | |
console.log(state); | |
if (state.pot.value < potGoal) { | |
return; | |
} else if(state.pot.value >= potGoal && !state.pot.timeoutStarted) { | |
state.pot.timeout = Date.now(); | |
state.pot.timeoutStarted = true; | |
} else { | |
let timeFromStart = Math.abs(state.pot.timeout - Date.now()); | |
if(timeFromStart< timeAfterPotGoal) { | |
return; | |
} else { | |
state.potNumber++; | |
state.pot.isClosed = true; | |
state.pot = new Pot(); | |
} | |
} | |
} | |
setInterval(editState, frequency); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment