diff --git a/SpecRunner.html b/SpecRunner.html index 0265dc18..061b0e1b 100644 --- a/SpecRunner.html +++ b/SpecRunner.html @@ -16,8 +16,8 @@ - - + + diff --git a/index.html b/index.html index 32e914c7..4b64407d 100644 --- a/index.html +++ b/index.html @@ -38,10 +38,10 @@

Splits

- + - + diff --git a/src/chronometer-centiseconds.js b/src/chronometer-centiseconds.js index 8337b5b6..c9bdd0db 100644 --- a/src/chronometer-centiseconds.js +++ b/src/chronometer-centiseconds.js @@ -1,37 +1,55 @@ class Chronometer { constructor() { // ... your code goes here + this.currentTime = 0; + this.intervalId = null; } start(printTimeCallback) { // ... your code goes here + this.intervalId = setInterval(() =>{ + this.currentTime += 10; + if (printTimeCallback) { + printTimeCallback(); + } + }, 10); } getMinutes() { // ... your code goes here + return Math.floor(this.currentTime / 60000); } getSeconds() { // ... your code goes here + return Math.floor((this.currentTime / 1000)) % 60; } getCentiseconds() { - // ... your code goes here + return Math.floor((this.currentTime % 1000) / 10); } computeTwoDigitNumber(value) { // ... your code goes here + return value.toString().padStart(2 , "0"); } stop() { // ... your code goes here + clearInterval(this.intervalId); + this.intervalId = null; } reset() { // ... your code goes here + clearInterval(this.intervalId); + this.currentTime = 0; + this.intervalId = null; } split() { // ... your code goes here + return `${this.computeTwoDigitNumber(this.getMinutes())}:${this.computeTwoDigitNumber(this.getSeconds())}:${this.computeTwoDigitNumber(this.getCentiseconds())}`; } } + diff --git a/src/chronometer.js b/src/chronometer.js index 83c75bd2..aa5a2b25 100644 --- a/src/chronometer.js +++ b/src/chronometer.js @@ -1,33 +1,47 @@ class Chronometer { constructor() { // ... your code goes here + this.currentTime = 0; + this.intervalId = null; } start(printTimeCallback) { // ... your code goes here + this.intervalId = setInterval(() =>{ + this.currentTime++; + if (printTimeCallback != null) { + printTimeCallback(); + } + }, 1000); } getMinutes() { // ... your code goes here + return parseInt(Math.floor(this.currentTime / 60)); } getSeconds() { // ... your code goes here + return this.currentTime % 60; } 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())}`; } }