-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
35 lines (35 loc) · 987 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var button = document.getElementById("click");
var clicks = [];
button.addEventListener('click', function () {
var millis = new Date().getTime();
clicks.push(millis);
});
var update = function () {
var totalClicks = 0;
var toRemove = [];
var i;
var millis = new Date().getTime();
for (i = 0; i < clicks.length; i++) {
if (millis - clicks[i] < 1000) {
totalClicks++;
}
else {
toRemove.push(i);
}
}
var j;
for (j = 0; j < toRemove.length; j++) {
clicks.splice(toRemove[j], 1);
}
if (Number(document.getElementById('highscore').innerText) < totalClicks) {
document.getElementById('highscore').innerText = totalClicks.toString();
}
if (totalClicks == 0) {
button.setAttribute('value', 'Click');
}
else {
button.setAttribute('value', totalClicks.toString() + '');
}
};
window.setInterval(update, 100);
//# sourceMappingURL=script.js.map