-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAPPY.js
More file actions
55 lines (49 loc) · 1.37 KB
/
LAPPY.js
File metadata and controls
55 lines (49 loc) · 1.37 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
console.log('LAPPY loaded');
const display=document.getElementById('display');
const buttons=document.querySelectorAll('button');
const start=document.getElementById('start');
const stop=document.getElementById('stop');
const reset=document.getElementById('reset');
let timer;
let hours=0;
let min=0;
let sec=0;
let time=0;
let running=false;
function startTimer(){
console.log('start timer');
running=true;
timer=setInterval(()=>{
if(running){
time++;
if(time===60){
time=0;
sec++;
}
if(sec===60){
sec=0;
min++;
}
if(min===60){
min=0;
hours++;
}
display.textContent=`${hours.toString().padStart(2,'0')}:${min.toString().padStart(2,'0')}:${sec.toString().padStart(2,'0')}:${time.toString().padStart(2,'0')}`;
// display.textContent=time.toFixed(2);
}
},10);
}
function pauseTimer(){
console.log('pause timer');
running=false;
}
function resetTimer(){
console.log('reset timer');
running=false;
clearInterval(timer);
hours=0;
min=0;
sec=0;
time=0;
display.textContent=`${hours.toString().padStart(2,'0')}:${min.toString().padStart(2,'0')}:${sec.toString().padStart(2,'0')}:${time.toString().padStart(2,'0')}`;
}