Skip to content

Instantly share code, notes, and snippets.

@almirsarajcic
Created July 28, 2016 06:13
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 almirsarajcic/3d3d219aeca1aeb10cb1b7b2fb067cc3 to your computer and use it in GitHub Desktop.
Save almirsarajcic/3d3d219aeca1aeb10cb1b7b2fb067cc3 to your computer and use it in GitHub Desktop.
var interval = 500.5,
container = $('#container'),
score = $('#score'),
lastScore = 0,
addend = -1,
clickCount = 0,
clickLimit = 40,
playButton = $('#play'),
restartButton = $('.restart');
function click() {
if (clickCount == clickLimit) {
setTimeout(checkScore, 500);
} else {
container.click();
clickCount++;
setTimeout(click, interval);
}
}
function checkScore() {
newScore = score.text();
if (newScore < 1000) {
console.log('Score: ' + newScore + ', interval: ' + interval + ' ms');
if (newScore < lastScore) {
addend *= -1;
}
interval += addend;
lastScore = newScore;
clickCount = 0;
restartButton.click();
click();
} else {
console.log('Success! Interval is ' + interval + ' ms.');
}
}
playButton.click();
click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment