diff --git a/index.html b/index.html index 32e914c7..4f65cb6a 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.js b/src/chronometer.js index 83c75bd2..11e446cc 100644 --- a/src/chronometer.js +++ b/src/chronometer.js @@ -1,33 +1,41 @@ class Chronometer { constructor() { - // ... your code goes here + this.currentTime = 0; + this.intervalId = null; } start(printTimeCallback) { - // ... your code goes here + this.intervalId = setInterval(() => { + this.currentTime += 1; + if (printTimeCallback !== undefined) { + printTimeCallback(); + } + }, 1000); } getMinutes() { - // ... your code goes here + return Math.floor(this.currentTime / 60); } getSeconds() { - // ... your code goes here + return this.currentTime % 60; } computeTwoDigitNumber(value) { - // ... your code goes here + return `00${value}`.slice(-2); } 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())}`; } }