-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripte.js
More file actions
37 lines (27 loc) · 824 Bytes
/
scripte.js
File metadata and controls
37 lines (27 loc) · 824 Bytes
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
36
37
let clicks = 0;
const TIMEOUT = 5000;
const display = document.querySelector("#display");
const button = document.querySelector("#button");
const counter = document.querySelector("#counter");
button.onclick = start;
function start() {
const startTime = Date.now();
display.textContent = formatTime(TIMEOUT);
counter.textContent = ++clicks;
button.onclick = () => {
counter.textContent = ++clicks;
};
const interval = setInterval(() => {
const delta = Date.now() - startTime;
display.textContent = formatTime(TIMEOUT - delta);
}, 10);
const timeout = setTimeout(() => {
button.onclick = null;
display.textContent = "Game Over";
clearInterval(interval);
clearTimeout(timeout);
}, TIMEOUT);
}
function formatTime(ms) {
return Number.parseFloat(ms / 1000).toFixed(3);
}