Update script.js
Browse files
script.js
CHANGED
@@ -10,15 +10,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
10 |
let testDuration = 15; // Duration in seconds
|
11 |
|
12 |
function startTest() {
|
|
|
13 |
clickCount = 0;
|
14 |
cpsDisplay.textContent = 'CPS: 0.00';
|
15 |
timerElement.textContent = testDuration;
|
16 |
-
|
17 |
clickButton.classList.add('white');
|
18 |
clickButton.textContent = clickCount;
|
19 |
|
|
|
20 |
intervalId = setInterval(updateTimer, 1000);
|
21 |
|
|
|
22 |
clickButton.removeEventListener('click', startTest);
|
23 |
clickButton.addEventListener('click', recordClick);
|
24 |
}
|
@@ -28,10 +30,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
28 |
timerElement.textContent = testDuration;
|
29 |
|
30 |
if (testDuration <= 0) {
|
|
|
31 |
clearInterval(intervalId);
|
32 |
clickButton.classList.remove('white');
|
33 |
-
clickButton.textContent = '
|
34 |
-
clickButton.
|
|
|
|
|
35 |
displayFinalCPS();
|
36 |
}
|
37 |
}
|
@@ -52,5 +57,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
52 |
cpsDisplay.textContent = `Final CPS: ${finalCPS.toFixed(2)}`;
|
53 |
}
|
54 |
|
|
|
55 |
clickButton.addEventListener('click', startTest);
|
56 |
});
|
|
|
10 |
let testDuration = 15; // Duration in seconds
|
11 |
|
12 |
function startTest() {
|
13 |
+
// Reset variables and UI elements
|
14 |
clickCount = 0;
|
15 |
cpsDisplay.textContent = 'CPS: 0.00';
|
16 |
timerElement.textContent = testDuration;
|
|
|
17 |
clickButton.classList.add('white');
|
18 |
clickButton.textContent = clickCount;
|
19 |
|
20 |
+
// Start the timer
|
21 |
intervalId = setInterval(updateTimer, 1000);
|
22 |
|
23 |
+
// Set button event listeners
|
24 |
clickButton.removeEventListener('click', startTest);
|
25 |
clickButton.addEventListener('click', recordClick);
|
26 |
}
|
|
|
30 |
timerElement.textContent = testDuration;
|
31 |
|
32 |
if (testDuration <= 0) {
|
33 |
+
// End the test
|
34 |
clearInterval(intervalId);
|
35 |
clickButton.classList.remove('white');
|
36 |
+
clickButton.textContent = 'Start';
|
37 |
+
clickButton.addEventListener('click', startTest);
|
38 |
+
|
39 |
+
// Display final CPS
|
40 |
displayFinalCPS();
|
41 |
}
|
42 |
}
|
|
|
57 |
cpsDisplay.textContent = `Final CPS: ${finalCPS.toFixed(2)}`;
|
58 |
}
|
59 |
|
60 |
+
// Initialize the button with the start event listener
|
61 |
clickButton.addEventListener('click', startTest);
|
62 |
});
|