diff --git a/src/chronometer.js b/src/chronometer.js index 83c75bd2..6a498491 100644 --- a/src/chronometer.js +++ b/src/chronometer.js @@ -1,33 +1,54 @@ class Chronometer { constructor() { // ... your code goes here + this.currentTime = 0; + this.intervalId = null; } start(printTimeCallback) { // ... your code goes here + if (this.intervalId) return; + + this.intervalId = setInterval(() => { + this.currentTime++; + + if (printTimeCallback) { + printTimeCallback(); + } + }, 1000); } getMinutes() { // ... your code goes here + return Math.floor(this.currentTime / 60); } getSeconds() { // ... your code goes here + return this.currentTime % 60; } computeTwoDigitNumber(value) { // ... your code goes here + return String(value).padStart(2, "0"); } stop() { // ... your code goes here + clearInterval(this.intervalId); + this.intervalId = null; } 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()); + + return `${minutes}:${seconds}`; } }