-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (68 loc) · 1.82 KB
/
index.js
File metadata and controls
80 lines (68 loc) · 1.82 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
const chronometer = new Chronometer();
const btnLeft = document.getElementById('btnLeft');
const btnRight = document.getElementById('btnRight');
const minDec = document.getElementById('minDec');
const minUni = document.getElementById('minUni');
const secDec = document.getElementById('secDec');
const secUni = document.getElementById('secUni');
const splits = document.getElementById('splits');
function printTime() {
printMinutes();
printSeconds();
}
function printMinutes() {
const minutes = chronometer.computeTwoDigitNumber(chronometer.getMinutes());
minDec.innerText = minutes[0];
minUni.innerText = minutes[1];
}
function printSeconds() {
const seconds = chronometer.computeTwoDigitNumber(chronometer.getSeconds());
secDec.innerText = seconds[0];
secUni.innerText = seconds[1];
}
function printSplit() {
const splitTime = chronometer.split();
const li = document.createElement('li');
li.innerText = splitTime;
li.className = 'list-item';
splits.appendChild(li);
}
function clearSplits() {
splits.innerHTML = '';
}
function setStopBtn() {
btnLeft.innerText = 'STOP';
btnLeft.className = 'btn stop';
}
function setSplitBtn() {
btnRight.innerText = 'SPLIT';
btnRight.className = 'btn split';
}
function setStartBtn() {
btnLeft.innerText = 'START';
btnLeft.className = 'btn start';
}
function setResetBtn() {
btnRight.innerText = 'RESET';
btnRight.className = 'btn reset';
}
btnLeft.addEventListener('click', () => {
if (btnLeft.classList.contains('start')) {
chronometer.start(printTime);
setStopBtn();
setSplitBtn();
} else {
chronometer.stop();
setStartBtn();
setResetBtn();
}
});
btnRight.addEventListener('click', () => {
if (btnRight.classList.contains('reset')) {
chronometer.reset();
clearSplits();
printTime();
} else {
printSplit();
}
});