diff --git a/SpecRunner.html b/SpecRunner.html index 0265dc18..544645dd 100644 --- a/SpecRunner.html +++ b/SpecRunner.html @@ -12,12 +12,12 @@ - - + + - - + + diff --git a/index.html b/index.html index 32e914c7..e32a332f 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..e7d0e986 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(); + }, 10); + + return printTimeCallback; } getMinutes() { - // ... your code goes here + return Math.floor(this.currentTime / 6000); } 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 + const newValue = value.toString(); + + if (newValue.length < 9 || newValue.length >= 0) { + let padTime = "0" + newValue; + return padTime.slice(-2); + } + + return newValue; } stop() { - // ... your code goes here + return clearInterval(this.intervalId) } reset() { - // ... your code goes here + return this.currentTime = 0 } split() { - // ... your code goes here - } + return `${this.computeTwoDigitNumber(this.getMinutes())}:${this.computeTwoDigitNumber(this.getSeconds())}.${this.computeTwoDigitNumber(this.getCentiseconds())}`; + + } +} \ No newline at end of file diff --git a/src/chronometer.js b/src/chronometer.js index 83c75bd2..e66fa50a 100644 --- a/src/chronometer.js +++ b/src/chronometer.js @@ -1,33 +1,53 @@ 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(); + }, 1000); + + return printTimeCallback; } 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 + const newValue = value.toString(); + + if (newValue.length < 9 || newValue.length >= 0) { + let padTime = "0" + newValue; + return padTime.slice(-2); + } + + return newValue; + + // if (value >= 0 || value <= 9){ + // const padTime = ('0' + value) + // return padTime.slice(-2).toString() + // } + // const result = value.toString(); + + // return result; } stop() { - // ... your code goes here + return clearInterval(this.intervalId) } reset() { - // ... your code goes here + return this.currentTime = 0 } split() { - // ... your code goes here + return `${this.computeTwoDigitNumber(this.getMinutes())}:${this.computeTwoDigitNumber(this.getSeconds())}` } }