diff --git a/SpecRunner.html b/SpecRunner.html index 0265dc18..58176f89 100644 --- a/SpecRunner.html +++ b/SpecRunner.html @@ -4,21 +4,24 @@ Jasmine Spec Runner v2.8.0 - + - - - + + - - - + + diff --git a/index.html b/index.html index 32e914c7..def40a9d 100644 --- a/index.html +++ b/index.html @@ -1,50 +1,49 @@ - - - - - JS Chronometer - - - - -
-

Splits

-
    -
-
- -
- -
-
- 00:00 - -
- 00 + + + + + JS Chronometer + + + +
+

Splits

+
    +
    + +
    + +
    +
    + 00:00 + +
    + 00 +
    + + +
    +
    - +
    +
    +
    +
    -
    -
    -
    -
    -
    -
    + + + + - - - - - - - - - - - - \ No newline at end of file + + + + diff --git a/src/chronometer-centiseconds.js b/src/chronometer-centiseconds.js index 8337b5b6..1d9c07c0 100644 --- a/src/chronometer-centiseconds.js +++ b/src/chronometer-centiseconds.js @@ -1,37 +1,67 @@ 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 (typeof printTimeCallback === "function") { + printTimeCallback(); + } + }, 10); } getMinutes() { // ... your code goes here + return Math.floor(this.currentTime / 6000); } getSeconds() { // ... your code goes here + return Math.floor(this.currentTime / 100 - this.getMinutes() * 60); } getCentiseconds() { // ... your code goes here + return ( + this.currentTime - (this.getSeconds() * 100 + this.getMinutes() * 6000) + ); } computeTwoDigitNumber(value) { // ... your code goes here + if (value < 10) { + return `0${value}`; + } + if (value < 100) { + return `${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())}`; } } + +const chronometer2 = new Chronometer(); +console.log(chronometer2.getCentiseconds(6122)); diff --git a/src/chronometer.js b/src/chronometer.js index 83c75bd2..b029bb99 100644 --- a/src/chronometer.js +++ b/src/chronometer.js @@ -1,33 +1,57 @@ 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 (typeof printTimeCallback === "function") { + printTimeCallback(); + } + }, 1000); } getMinutes() { // ... your code goes here + return Math.floor(this.currentTime / 60); } getSeconds() { // ... your code goes here + return this.currentTime - this.getMinutes() * 60; } computeTwoDigitNumber(value) { // ... your code goes here + if (value < 10) { + return `0${value}`; + } + return value < 60 ? `${value}` : alert("Error"); } 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())}`; } } + +// const chronometer2 = new Chronometer(); +// console.log(chronometer2.computeTwoDigitNumber(13));