Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/chronometer.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,60 @@
class Chronometer {
constructor() {
// ... your code goes here
this.currentTime = 0;
this.intervalId = null;
}

start(printTimeCallback) {
// ... your code goes here
if (this.intervalId) return; // Prevent multiple intervals
this.intervalId = setInterval(() => {
this.currentTime++;
if (printTimeCallback) {
printTimeCallback();
}
}, 1000);
}

getMinutes() {
// ... your code goes here
return Math.floor(this.currentTime / 60);
}

getSeconds() {
// ... your code goes here
return this.currentTime % 60;
}

getMilliseconds() {
// ... your code goes here
return (this.currentTime % 1) * 1000;
}

computeTwoDigitNumber(value) {
// ... your code goes here
return value < 10 ? `0${value}` : `${value}`;
}

stop() {
// ... your code goes here
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = null;
}
}

reset() {
// ... your code goes here
this.currentTime = 0;
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = null;
}
}

split() {
// ... your code goes here
const minutes = this.computeTwoDigitNumber(this.getMinutes());
const seconds = this.computeTwoDigitNumber(this.getSeconds());
return `${minutes}:${seconds}`;
}
}