diff --git a/SpecRunner.html b/SpecRunner.html index 0265dc18..645ab227 100644 --- a/SpecRunner.html +++ b/SpecRunner.html @@ -12,12 +12,12 @@ - - + + - - + + 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..f69306b3 100644 --- a/src/chronometer-centiseconds.js +++ b/src/chronometer-centiseconds.js @@ -1,37 +1,52 @@ 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) printTimeCallback(this.currentTime); + }, 10); } getMinutes() { // ... your code goes here + return Math.floor(this.currentTime / (60*100)); + } getSeconds() { // ... your code goes here + return Math.floor(this.currentTime/100 % 60); } getCentiseconds() { // ... your code goes here + return Math.floor(this.currentTime%100 ); + } computeTwoDigitNumber(value) { // ... your code goes here + return value < 10 ? `0${value}` :`${value}`; } 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())}`; } } diff --git a/src/chronometer.js b/src/chronometer.js index 83c75bd2..900f7ede 100644 --- a/src/chronometer.js +++ b/src/chronometer.js @@ -1,33 +1,45 @@ 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) printTimeCallback(this.currentTime); + }, 1000); } getMinutes() { // ... your code goes here + return Math.floor(this.currentTime / 60); } getSeconds() { // ... your code goes here + return Math.floor(this.currentTime % 60); } computeTwoDigitNumber(value) { // ... your code goes here + return value < 10 ? `0${value}` :`${value}`; } 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())}`; } } diff --git a/src/index.js b/src/index.js index 385caac5..294fd40f 100644 --- a/src/index.js +++ b/src/index.js @@ -84,4 +84,4 @@ btnRight.addEventListener('click', () => { } else { printSplit(); } -}); \ No newline at end of file +});