-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
60 lines (48 loc) · 1.35 KB
/
main.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
//*****CONECTAR CON EL CONTADOR QUE PARTE DE 0
let chronometer = document.getElementById("chronometer");
//*****CONECTAR CON LA BOTONERA
let start = document.getElementById("startButton");
let reset = document.getElementById("resetButton");
let rec = document.getElementById("recButton");
let store = document.getElementById("storeTimes");
//***** */
let time = 0, interval = 0;
let checker = false;
//****INICIAR - PARAR CONTADOR ****/
init();
function init() {
start.addEventListener('click', startChrono);
reset.addEventListener('click', resetChrono);
rec.addEventListener('click', recChrono);
}
//****startChrono*****/
function startChrono() {
if(checker==false){
interval = setInterval(function() {
time += 0.01;
chronometer.innerHTML = time.toFixed(2);
}, 10);
checker = true;
} else {
checker = false;
clearInterval(interval);
}
};
//****resetChrono*****/
function resetChrono() {
checker = false;
time = 0;
chronometer.innerHTML = time + '.00';
clearInterval(interval);
while(storeTimes.firstChild) {
storeTimes.removeChild(storeTimes.firstChild);
}
}
//****recChrono*****/
function recChrono() {
let p = document.createElement('ul');
p.innerHTML = `
<li>Time : ${time.toFixed(2)}</li>
`;
storeTimes.appendChild(p);
}