-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
71 lines (55 loc) · 1.38 KB
/
app.js
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
//Developer: Muhammad wasi
//start of code
var ms = 0; s = 0; m = 0; //milli,seconds,minutes are = 0
var timer;//take name as timer..//
var stopwatch = document.querySelector('.stopwatch');
var lapsContainer = document.querySelector('.laps');//we take class in html and put here//
function start(){
if(!timer){
timer = setInterval(run,10);
}
}
function run(){
stopwatch.textContent = getTimer()
ms++;
if(ms == 100){
ms = 0;
s++;
}
if(s == 60){
s = 0;
m++;
}
}//for start the function
function pause(){
stopTimer();
}//pause
function stop(){
stopTimer();
ms = 0;
s = 0;
m = 0;
stopwatch.textContent = getTimer()
}//stop and reset to factory mode
function stopTimer(){
clearInterval(timer);
timer = false;
}//pause the function
function getTimer(){
return (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s) + ":" + (ms < 10 ? "0" + ms : ms);
}//for no less then 10 we take 0 before that like 02:09:60...//
function restart(){
stop();
start();
}//restart
function laps(){
if(timer){
var li = document.createElement('li');
li.innerText = getTimer();
lapsContainer.appendChild(li);
}
}//laps
function resetlaps(){
lapsContainer.innerHTML = '';
}//reset laps
//end of code