forked from avinash201199/stopwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
134 lines (110 loc) · 3.25 KB
/
script.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
var hr = 0;
var min = 0;
var sec = 0;
var count = 0;
var timer = false;
var lapCounter = 1;
const audio = new Audio();
audio.src = "audio/sound_trim.mp3"
function start() {
audio.play();
if (!timer){
timer = true;
document.getElementById("start").innerHTML = '<i class="far fa-pause-circle"></i> Pause';
stopwatch();
}
else
{
timer=false;
document.getElementById("start").innerHTML = '<i class="far fa-play-circle"></i> Start';
}
}
/*function stop() {
timer = false
}
*/
function reset() {
//hiding record container div
document.getElementById("record-container").style.display = "none";
audio.play();
timer = false;
document.getElementById("start").innerHTML = '<i class="far fa-play-circle"></i> Start';
hr = 0;
min = 0;
sec = 0;
count = 0;
document.getElementById("hr").innerHTML = "00";
document.getElementById("min").innerHTML = "00";
document.getElementById("sec").innerHTML = "00";
document.getElementById("count").innerHTML = "00";
document.getElementById("record-table-body").innerHTML = "";
lapCounter = 1;
}
let timeoutId;
function stopwatch() {
clearTimeout(timeoutId);
if (timer == true)
count = count + 1;
if (count == 99) {
sec = sec + 1;
count = 0;
}
if (sec == 59) {
min = min + 1;
sec = 0;
}
if (min == 59) {
hr = hr + 1;
min = 0;
sec = 0;
}
var hrString = hr;
var minString = min;
var secString = sec;
var countString = count;
if (hr < 10) {
hrString = "0" + hrString;
}
if (min < 10) {
minString = "0" + minString;
}
if (sec < 10) {
secString = "0" + secString;
}
if (count < 10) {
countString = "0" + countString;
}
document.getElementById("hr").innerHTML = hrString;
document.getElementById("min").innerHTML = minString;
document.getElementById("sec").innerHTML = secString;
document.getElementById("count").innerHTML = countString;
timeoutId = setTimeout("stopwatch()", 10);
}
function lap() {
//displaying record container div
document.getElementById("record-container").style.display = "block";
audio.play();
var lap_time = document.getElementById("hr").innerHTML + ":"
+ document.getElementById("min").innerHTML + ":"
+ document.getElementById("sec").innerHTML + ":"
+ document.getElementById("count").innerHTML;
const table = document.getElementById("record-table-body");
const row = table.insertRow(0);
const no_cell = row.insertCell(0);
const time_cell = row.insertCell(1);
no_cell.innerHTML = lapCounter;
time_cell.innerHTML = lap_time;
lapCounter++;
}
function clearLap() {
//hiding record container div
document.getElementById("record-container").style.display = "none";
audio.play();
document.getElementById('record-table-body').innerHTML = '';
lapCounter=1;
}
let date;
setInterval(() => {
date = new Date().toString();
document.getElementById('d1').innerHTML = date;
}, 1000);