Created
July 28, 2016 06:13
-
-
Save almirsarajcic/3d3d219aeca1aeb10cb1b7b2fb067cc3 to your computer and use it in GitHub Desktop.
This file contains 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
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