Fix for time inconsistency
This commit is contained in:
parent
79593a0434
commit
74d35aae24
1 changed files with 4 additions and 4 deletions
|
@ -70,6 +70,7 @@ let isHolding = false;
|
||||||
let buttonText = holdButton.querySelector('span');
|
let buttonText = holdButton.querySelector('span');
|
||||||
let messageInterval;
|
let messageInterval;
|
||||||
let lastMessageTime = 0;
|
let lastMessageTime = 0;
|
||||||
|
let finalTime = 0;
|
||||||
const MESSAGE_UPDATE_INTERVAL = 3000; // 3 seconds between messages
|
const MESSAGE_UPDATE_INTERVAL = 3000; // 3 seconds between messages
|
||||||
|
|
||||||
// Random messages while holding
|
// Random messages while holding
|
||||||
|
@ -241,8 +242,8 @@ function formatTime(ms) {
|
||||||
// Update timer display
|
// Update timer display
|
||||||
function updateTimer() {
|
function updateTimer() {
|
||||||
const currentTime = Date.now();
|
const currentTime = Date.now();
|
||||||
const elapsedTime = currentTime - startTime;
|
finalTime = currentTime - startTime;
|
||||||
timer.textContent = formatTime(elapsedTime);
|
timer.textContent = formatTime(finalTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get random message from array
|
// Get random message from array
|
||||||
|
@ -264,9 +265,8 @@ function stopHold() {
|
||||||
isHolding = false;
|
isHolding = false;
|
||||||
clearInterval(timerInterval);
|
clearInterval(timerInterval);
|
||||||
clearInterval(messageInterval);
|
clearInterval(messageInterval);
|
||||||
const finalTime = Date.now() - startTime;
|
|
||||||
|
|
||||||
// Show result
|
// Show result using the final time we already calculated
|
||||||
result.textContent = `${formatTime(finalTime)} - ${getRandomMessage(resultMessages)}`;
|
result.textContent = `${formatTime(finalTime)} - ${getRandomMessage(resultMessages)}`;
|
||||||
resultContainer.classList.add('show');
|
resultContainer.classList.add('show');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue