-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (32 loc) · 957 Bytes
/
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
let [segundos, minutos, horas] = [0, 0, 0];
let displayTempo = document.getElementById("displayTempo");
let temporizador = null;
function cronometro() {
segundos++;
if (segundos == 60) {
segundos = 0;
minutos++;
if (minutos == 60) {
minutos = 0;
horas++;
}
}
let h = horas < 10 ? "0" + horas : horas;
let m = minutos < 10 ? "0" + minutos : minutos;
let s = segundos < 10 ? "0" + segundos : segundos;
displayTempo.innerHTML = h + ":" + m + ":" + s;
}
function iniciarCronometro() {
if (temporizador !== null) {
clearInterval(temporizador);
}
temporizador = setInterval(cronometro, 1000);
}
function pararIniciarCronometro() {
clearInterval(temporizador);
}
function reiniciarCronometro() {
clearInterval(temporizador);
[segundos, minutos, horas] = [0, 0, 0];
displayTempo.innerHTML = "00:00:00";
}