diff --git a/SpecRunner.html b/SpecRunner.html index 0265dc18..3086c4d0 100644 --- a/SpecRunner.html +++ b/SpecRunner.html @@ -1,25 +1,28 @@ - - - Jasmine Spec Runner v2.8.0 + + + Jasmine Spec Runner v2.8.0 - - + + - - - + + + - - - + + - - - + + + + - - - + diff --git a/index.html b/index.html index 32e914c7..f42830e8 100644 --- a/index.html +++ b/index.html @@ -1,50 +1,49 @@ - - - - - JS Chronometer - - - - -
-

Splits

-
    -
-
- -
- -
-
- 00:00 - -
- 00 -
- - -
-
- -
-
-
-
-
- - - - - - - - - - - - - - \ No newline at end of file + + + + + JS Chronometer + + + +
+

Splits

+
    +
    + +
    + +
    +
    + 00:00 + +
    + 00 +
    + + + +
    +
    + +
    +
    +
    +
    +
    + + + + + + + + + + + diff --git a/src/chronometer-centiseconds.js b/src/chronometer-centiseconds.js index 8337b5b6..759504bf 100644 --- a/src/chronometer-centiseconds.js +++ b/src/chronometer-centiseconds.js @@ -1,37 +1,60 @@ class Chronometer { - constructor() { - // ... your code goes here - } - - start(printTimeCallback) { - // ... your code goes here - } - - getMinutes() { - // ... your code goes here - } - - getSeconds() { - // ... your code goes here - } - - getCentiseconds() { - // ... your code goes here - } - - computeTwoDigitNumber(value) { - // ... your code goes here - } - - stop() { - // ... your code goes here - } - - reset() { - // ... your code goes here - } - - split() { - // ... your code goes here - } + 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 / 6000) + } + + getSeconds() { + // ... your code goes here + return Math.floor((this.currentTime % 6000) / 100) + } + + 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 + console.log( + `${this.getMinutes()}:${this.getSeconds()}.${this.getCentiseconds()}` + ) + 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..d3621226 100644 --- a/src/chronometer.js +++ b/src/chronometer.js @@ -1,33 +1,56 @@ class Chronometer { - constructor() { - // ... your code goes here - } + constructor() { + // ... your code goes here + this.currentTime = 0 + this.intervalId = null + } - start(printTimeCallback) { - // ... your code goes here - } + start(printTimeCallback) { + // ... your code goes here - getMinutes() { - // ... your code goes here - } + this.intervalId = setInterval(() => { + this.currentTime++ + if (printTimeCallback) { + printTimeCallback(this.currentTime) + } + }, 1000) + } - getSeconds() { - // ... your code goes here - } + getMinutes() { + // ... your code goes here + return Math.floor(this.currentTime / 60) + } - computeTwoDigitNumber(value) { - // ... your code goes here - } + getSeconds() { + // ... your code goes here + return this.currentTime % 60 + } - stop() { - // ... your code goes here - } + computeTwoDigitNumber(value) { + // ... your code goes here - reset() { - // ... your code goes here - } + return `${value.toString().padStart(2, '0')}` + } - split() { - // ... your code goes here - } + stop() { + // ... your code goes here + clearInterval(this.intervalId) + } + + reset() { + // ... your code goes here + this.currentTime = 0 + } + + split() { + // ... your code goes here + console.log( + `${this.getMinutes().toString().padStart(2, '0')}:${this.getSeconds() + .toString() + .padStart(2, '0')}` + ) + return `${this.getMinutes().toString().padStart(2, '0')}:${this.getSeconds() + .toString() + .padStart(2, '0')}` + } }