Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
54 lines (44 loc) · 1.48 KB
/
Copy pathapp.js
File metadata and controls
54 lines (44 loc) · 1.48 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
let secondsElapsed = 0;
let interval = null;
let hours = document.querySelector("#hours");
let minutes = document.querySelector("#minutes");
let seconds = document.querySelector("#seconds");
let previousValue = document.querySelector(".prev");
let nextValue = document.querySelector(".next");
function setTimeToClock() {
const hrs = Math.floor(secondsElapsed / 3600);
const mins = Math.floor((secondsElapsed % 3600) / 60);
const secs= Math.floor(secondsElapsed % 60);
hours.innerHTML = String(hrs).padStart(2, '0');
minutes.innerHTML = String(mins).padStart(2, '0');
seconds.innerHTML = String(secs).padStart(2, '0');
const pre = secs === 0 ? 59:secs - 1;
const next = secs === 59 ? 1:secs + 1;
previousValue.innerHTML = String(pre).padStart(2,'0');
nextValue.innerHTML = String(next).padStart(2,'0');
}
function timer() {
secondsElapsed ++;
setTimeToClock();
}
function startStop() {
if (interval)
{
clearInterval(interval);
interval = null;
document.querySelector(".start").innerHTML = "Start";
document.querySelector(".start").style.backgroundColor = "rgb(94, 85, 113)";
}
else
{
interval = setInterval(timer,1000);
document.querySelector(".start").innerHTML = "Pause";
document.querySelector(".start").style.backgroundColor = "rgb(181, 82, 95)";
}
}
function resetClock() {
clearInterval(interval);
interval = null;
secondsElapsed = 0;
setTimeToClock();
}