-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (31 loc) · 1.22 KB
/
app.js
File metadata and controls
39 lines (31 loc) · 1.22 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
const start = () => displaySection("menu-section");
const choose = () => displaySection("timer-section");
const stop = () => displaySection("done-section");
const finish = () => displaySection("start-section");
const displaySection = (sectionId) => {
// hide all section elements except section in parameter
document.querySelectorAll("section").forEach(el => el.style.display = 'none');
document.getElementById(sectionId).style.display = 'block';
};
const startTimerFast = () => startTimer(10);
const startTimerSoft = () => startTimer(3 * 60);
const startTimerHard = () => startTimer(7 * 60);
const startTimer = (seconds) => {
choose();
const timerDisplay = document.getElementById("timer");
let duration = seconds;
const timerStep = () => {
let minutes = Math.floor(duration / 60);
let seconds = duration % 60;
seconds = seconds < 10 ? "0" + seconds : seconds;
timerDisplay.textContent = `${minutes}:${seconds}`;
if (duration <= 0) {
clearInterval(countdown);
timerDisplay.textContent = "";
stop();
}
duration--;
};
timerStep(); // remove initial delay
const countdown = setInterval(timerStep, 1000);
};