-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathindex.js
More file actions
121 lines (85 loc) · 2.86 KB
/
Copy pathindex.js
File metadata and controls
121 lines (85 loc) · 2.86 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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();
}
function printMinutes() {
const minutes = chronometer.computeTwoDigitNumber(chronometer.getMinutes());
minDecElement.innerHTML = minutes.slice(0, 1);
minUniElement.innerHTML = minutes.slice(1);
}
function printSeconds() {
const seconds = chronometer.computeTwoDigitNumber(chronometer.getSeconds())
secDecElement.innerHTML = seconds[0]
secUniElement.innerHTML = seconds[1]
}
// ==> BONUS
function printMilliseconds() {
const milliSeconds = chronometer.computeTwoDigitNumber(chronometer.getMilliseconds())
milDecElement.innerHTML = milliSeconds.slice(0, 1)
milUniElement.innerHTML = milliSeconds.slice(1)
}
function printSplit() {
// ... your code goes here
}
function clearSplits() {
// ... your code goes here
}
function setStopBtn() {
// ... your code goes here
}
function setSplitBtn() {
// ... your code goes here
}
function setStartBtn() {
}
function setResetBtn() {
// ... your code goes here
}
//HAY QUE HACER UN toogle (alternar estados)
// Start/Stop Button
btnLeftElement.addEventListener('click', () => {
if (btnLeftElement.innerText === 'START') {
btnLeftElement.innerText = 'STOP';
btnRightElement.innerText = 'SPLIT';
btnLeftElement.className = "btn stop";
btnRightElement.className = 'btn split';
chronometer.start(printTime);
} else if (btnLeftElement.innerText === 'STOP') {
btnLeftElement.innerText = 'START';
btnRightElement.innerText = 'RESET';
btnLeftElement.className = "btn start";
btnRightElement.className = "btn reset";
chronometer.stop()
}
}
);
// Reset/Split Button
btnRightElement.addEventListener('click', () => {
if (btnRightElement.innerText === "SPLIT") {
const tablaSplits = document.getElementById('splits'); //es mejor meterlos fuera de la funcion?
const newSplit = document.createElement('li');
tablaSplits.appendChild(newSplit);
newSplit.innerText = chronometer.split()
}
else if (btnRightElement.innerText === "RESET") {
chronometer.reset()
const ilSplits = document.querySelectorAll("#splits li")
const ilSplitsArr = [...ilSplits]
for (let split of ilSplitsArr) {
split.remove();
};
}
})