-
00
+
+
+
+
+
JS Chronometer
+
+
+
+
+
+
+
+
+
+
00:00
+
+
+ 00
+
+
+
+
+
-
+
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+
+
diff --git a/src/chronometer.js b/src/chronometer.js
index 83c75bd2..25e2bb95 100644
--- a/src/chronometer.js
+++ b/src/chronometer.js
@@ -1,33 +1,46 @@
class Chronometer {
constructor() {
- // ... your code goes here
+ this.currentTime = 0;
+ this.intervalId = null;
}
start(printTimeCallback) {
- // ... your code goes here
+ this.intervalId = setInterval(() => {
+ this.currentTime += 1;
+
+ if (printTimeCallback) {
+ printTimeCallback();
+ }
+ }, 10);
}
getMinutes() {
- // ... your code goes here
+ return Math.floor(this.currentTime / 6000);
}
getSeconds() {
- // ... your code goes here
+ return Math.floor(this.currentTime / 100) % 60;
+ }
+
+ getCentiseconds() {
+ return this.currentTime % 100;
}
computeTwoDigitNumber(value) {
- // ... your code goes here
+ return value.toString().padStart(2, "0");
}
stop() {
- // ... your code goes here
+ clearInterval(this.intervalId);
}
reset() {
- // ... your code goes here
+ this.currentTime = 0;
}
split() {
- // ... your code goes here
+ return `${this.computeTwoDigitNumber(this.getMinutes())}:
+ ${this.computeTwoDigitNumber(this.getSeconds())}:
+ ${this.computeTwoDigitNumber(this.getCentiseconds())}`;
}
}