+
0
0
:
0
0
+
0
0
diff --git a/javascript/chronometer.js b/javascript/chronometer.js
index 7a1349680..1b9791099 100644
--- a/javascript/chronometer.js
+++ b/javascript/chronometer.js
@@ -1,34 +1,48 @@
class Chronometer {
constructor() {
- // ... your code goes here
+ this.currentTime = 0;
+ this.intervalId = null;
}
start(callback) {
- // ... your code goes here
+ this.intervalId = setInterval(() => {
+ this.currentTime++;
+
+ if (typeof callback === 'function') {
+ callback();
+ }
+ }, 10);
}
getMinutes() {
- // ... your code goes here
+ return Math.floor(this.currentTime / 6000);
}
getSeconds() {
- // ... your code goes here
+ return Math.floor((this.currentTime % 6000) / 100);
+ }
+
+ getMilliseconds() {
+ return this.currentTime % 100;
}
computeTwoDigitNumber(value) {
- // ... your code goes here
+ return value < 10 ? '0' + value : value.toString();
}
stop() {
- // ... your code goes here
+ clearInterval(this.intervalId);
}
reset() {
- // ... your code goes here
+ this.currentTime = 0;
}
split() {
- // ... your code goes here
+ const minutes = this.computeTwoDigitNumber(this.getMinutes());
+ const seconds = this.computeTwoDigitNumber(this.getSeconds());
+ const milliseconds = this.computeTwoDigitNumber(this.getMilliseconds());
+ return `${minutes}:${seconds}:${milliseconds}`;
}
}
@@ -37,3 +51,6 @@ class Chronometer {
if (typeof module !== 'undefined') {
module.exports = Chronometer;
}
+
+
+
diff --git a/javascript/index.js b/javascript/index.js
index fb3a43ab4..311a25741 100644
--- a/javascript/index.js
+++ b/javascript/index.js
@@ -14,52 +14,87 @@ const milUniElement = document.getElementById('milUni');
const splitsElement = document.getElementById('splits');
function printTime() {
- // ... your code goes here
+ printMinutes();
+ printSeconds();
+ printMilliseconds();
}
function printMinutes() {
- // ... your code goes here
+ const minutes = chronometer.computeTwoDigitNumber(chronometer.getMinutes());
+ minDecElement.innerText = minutes[0];
+ minUniElement.innerText = minutes[1];
}
function printSeconds() {
- // ... your code goes here
+ const seconds = chronometer.computeTwoDigitNumber(chronometer.getSeconds());
+ secDecElement.innerText = seconds[0];
+ secUniElement.innerText = seconds[1];
}
-// ==> BONUS
+
+
+
function printMilliseconds() {
- // ... your code goes here
+ const milliseconds = chronometer.getMilliseconds();
+ milDecElement.innerText = Math.floor(milliseconds / 10);
+ milUniElement.innerText = milliseconds % 10;
}
function printSplit() {
- // ... your code goes here
+ const splitTime = chronometer.split();
+ const li = document.createElement('li');
+ li.classList.add('list-item');
+ li.innerText = splitTime;
+ splitsElement.appendChild(li);
}
function clearSplits() {
- // ... your code goes here
+ splitsElement.innerHTML = '';
}
+
function setStopBtn() {
- // ... your code goes here
+ btnLeftElement.innerText = 'STOP';
+ btnLeftElement.className = 'btn stop';
}
function setSplitBtn() {
- // ... your code goes here
+ btnRightElement.innerText = 'SPLIT';
+ btnRightElement.className = 'btn split';
}
function setStartBtn() {
- // ... your code goes here
+ btnLeftElement.innerText = 'START';
+ btnLeftElement.className = 'btn start';
}
function setResetBtn() {
- // ... your code goes here
+ btnRightElement.innerText = 'RESET';
+ btnRightElement.className = 'btn reset';
}
+
// Start/Stop Button
btnLeftElement.addEventListener('click', () => {
- // ... your code goes here
+ if (btnLeftElement.classList.contains('start')) {
+ chronometer.start(printTime);
+ setStopBtn();
+ setSplitBtn();
+ } else {
+ chronometer.stop();
+ setStartBtn();
+ setResetBtn();
+ }
});
// Reset/Split Button
btnRightElement.addEventListener('click', () => {
- // ... your code goes here
+ if (btnRightElement.classList.contains('reset')) {
+ chronometer.reset();
+ printTime();
+ clearSplits();
+ } else {
+ printSplit();
+ }
});
+
diff --git a/styles/style.css b/styles/style.css
index 695d4bfad..e6a62fa8a 100644
--- a/styles/style.css
+++ b/styles/style.css
@@ -33,10 +33,22 @@ body {
text-align: center;
width: 220px;
display:flex;
+ flex-direction: column;
align-items:center;
justify-content:center;
}
+
+#time-container {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 85px;
+ margin-bottom: 35px;
+ position: relative;
+
+}
+
#splits-container {
font-size: 20px;
font-weight: 100;
@@ -51,8 +63,19 @@ body {
#milliseconds {
font-size: 36px;
+ align-self: flex-end;
+ padding-right: 20px;
position: absolute;
- top: 20px;
+ top: 110px;
+letter-spacing: -3px;
+
+}
+
+
+#milDec,
+#milUni {
+ width: 14px;
+
}
.leash {
@@ -124,3 +147,6 @@ body {
.btn.split {
background: #0851ab;
}
+
+
+