Skip to content

Commit 6d4e706

Browse files
committed
- fix timer accuracy in button mashing game
- replace manual `timer` decrement with actual elapsed time calculation - use `Date` objects to track precise timing - add `Math.max()` to prevent negative timer values - maintain same 10-second game duration with more accurate timing
1 parent b4a9699 commit 6d4e706

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

games/human_benchmark/js/button_mashing.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ $(function () {
5252
mashedButton = '';
5353
$("#mashing-counter").text(totalPresses);
5454
startTime = new Date();
55-
var timer = 10;
5655
var timerInterval = setInterval(function () {
57-
timer -= 0.01;
58-
$("#mashing-timer").text(timer.toFixed(3));
59-
if (timer <= 0) {
56+
var currentTime = new Date();
57+
var elapsedSeconds = (currentTime - startTime) / 1000;
58+
var remainingTime = Math.max(10 - elapsedSeconds, 0);
59+
$("#mashing-timer").text(remainingTime.toFixed(3));
60+
61+
if (remainingTime <= 0) {
6062
clearInterval(timerInterval);
6163
endTime = new Date();
6264
$("#mashing-instruction").text("Please wait before restarting...");

0 commit comments

Comments
 (0)