-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
78 lines (59 loc) · 1.99 KB
/
app.js
File metadata and controls
78 lines (59 loc) · 1.99 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
let timer;
const totalTime = 60;
let timeLeft = totalTime;
let isPaused = false;
const startButton = document.querySelector(".start");
const buttonS = document.querySelector(".pause");
const buttonR = document.querySelector(".resume");
const buttonD = document.querySelector(".delete");
function visibility(start, pause, resume, deleteb) {
startButton.style.display = start ? "inline-block" : "none";
buttonS.style.display = pause ? "inline-block" : "none";
buttonR.style.display = resume ? "inline-block" : "none";
buttonD.style.display = deleteb ? "inline-block" : "none";
}
function startTimer() {
if (timer || isPaused) {return};
const reloj = document.querySelector('.conteo');
visibility(false, true, false, true);
timer = setInterval(() => {
let minutes = Math.floor(timeLeft / 60);
let seconds = timeLeft % 60;
minutes = minutes < 10
? '0' + minutes
: minutes;
seconds = seconds < 10
? '0' + seconds
: seconds;
reloj.textContent = `${minutes}:${seconds}`;
if (timeLeft <= 0) {
clearInterval(timer);
timer = null;
}
timeLeft--;
}, 1000);
};
function pauseTimer() {
if (!timer) return;
clearInterval(timer);
timer= null;
isPaused = true;
visibility(false, false, true, true);
};
function resetTimer() {
clearInterval(timer);
timer = null;
timeLeft = totalTime;
const reloj = document.querySelector('.conteo');
reloj.textContent = '01:00';
visibility(true, false, false, false);
};
function resumeTimer() {
if (timer || !isPaused) {return;};
isPaused = false;
startTimer();
};
startButton.addEventListener("click", startTimer);
buttonS.addEventListener("click", pauseTimer);
buttonD.addEventListener("click", resetTimer);
buttonR.addEventListener("click", resumeTimer);