-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathindex.js
More file actions
99 lines (82 loc) · 2.5 KB
/
index.js
File metadata and controls
99 lines (82 loc) · 2.5 KB
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
const chronometer = new Chronometer();
// get the buttons:
const btnLeftElement = document.getElementById('btnLeft');
const btnRightElement = document.getElementById('btnRight');
// get the DOM elements that will serve us to display the time:
const minDecElement = document.getElementById('minDec');
const minUniElement = document.getElementById('minUni');
const secDecElement = document.getElementById('secDec');
const secUniElement = document.getElementById('secUni');
const milDecElement = document.getElementById('milDec');
const milUniElement = document.getElementById('milUni');
const splitsElement = document.getElementById('splits');
function printTime() {
printMinutes();
printSeconds();
printMilliseconds(); // Bonus
}
function printMinutes() {
const minutes = chronometer.computeTwoDigitNumber(chronometer.getMinutes());
minDecElement.innerText = minutes[0];
minUniElement.innerText = minutes[1];
}
function printSeconds() {
const seconds = chronometer.computeTwoDigitNumber(chronometer.getSeconds());
secDecElement.innerText = seconds[0];
secUniElement.innerText = seconds[1];
}
// ==> BONUS
function printMilliseconds() {
const milliseconds = chronometer.computeTwoDigitNumber(
chronometer.getMilliseconds()
);
milDecElement.innerText = milliseconds[0];
milUniElement.innerText = milliseconds[1];
}
function printSplit() {
const li = document.createElement('li');
li.className = 'list-item';
li.innerText = chronometer.split();
splitsElement.appendChild(li);
}
function clearSplits() {
splitsElement.innerText = ''; // Limpia el contenido de la lista de elementos
}
function setStopBtn() {
btnLeftElement.className = 'btn stop';
btnLeftElement.innerText = 'STOP';
}
function setSplitBtn() {
btnRightElement.className = 'btn split';
btnRightElement.innerText = 'SPLIT';
}
function setStartBtn() {
btnLeftElement.className = 'btn start';
btnLeftElement.innerText = 'START';
}
function setResetBtn() {
btnRightElement.className = 'btn reset';
btnRightElement.innerText = 'RESET';
}
// Start/Stop Button
btnLeftElement.addEventListener('click', () => {
if (btnLeftElement.classList.contains('start')) {
chronometer.start(printTime);
setStopBtn();
setSplitBtn();
} else {
chronometer.stop();
setStartBtn();
setResetBtn();
}
});
// Reset/Split Button
btnRightElement.addEventListener('click', () => {
if (btnRightElement.classList.contains('reset')) {
chronometer.reset();
printTime();
clearSplits();
} else {
printSplit();
}
});