Skip to content

Instantly share code, notes, and snippets.

@mrandri19
Created July 3, 2016 18:20
Show Gist options
  • Save mrandri19/eabd1062c164f08dde509052eea80573 to your computer and use it in GitHub Desktop.
Save mrandri19/eabd1062c164f08dde509052eea80573 to your computer and use it in GitHub Desktop.
'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