-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstopwatch.js
70 lines (46 loc) · 1.38 KB
/
stopwatch.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
var horas = 0
var minutos = 0
var segundos = 0
var milisegundos = 0
var cronometroAtivado = false;
let crono;
function cronometro() {
document.getElementById('cronometro').innerText = concatenar(horas) + ':' + concatenar(minutos) + ':' + concatenar(segundos) + '.' + milisegundos;
if((milisegundos += 10) == 1000) {
milisegundos = 0;
segundos++
}
if(segundos == 60) {
segundos = 0;
minutos++
}
if(minutos == 60) {
minutos = 0;
horas++;
}
}
function iniciarCronometro() {
if(cronometroAtivado == false) {
cronometroAtivado = true;
crono = setInterval(() => { cronometro(); }, 10);
} else if(cronometroAtivado == true) {
$.notify("You already have a stopwatch active. Pause or restart it.");
}
}
function pause() {
cronometroAtivado = false;
clearInterval(crono);
}
function reset() {
clearInterval(crono);
cronometroAtivado = false;
horas = 0;
minutos = 0;
segundos = 0;
milisegundos = 0;
document.getElementById('cronometro').innerText = '00:00:00.000'
}
/* Concatening 0 if the value passed by argument is >= 10 */
function concatenar(input) {
return input >= 10 ? input : `0${input}`
}