Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created January 4, 2020 07:59
Show Gist options
  • Save sandrabosk/d6e575ac3ce9fecdd9b161414a624771 to your computer and use it in GitHub Desktop.
Save sandrabosk/d6e575ac3ce9fecdd9b161414a624771 to your computer and use it in GitHub Desktop.
class Chronometer {
constructor() {
this.currentTime = 0;
this.intervalId = 0;
}
startClick() {
this.intervalId = setInterval(() => this.currentTime++, 1000);
}
getMinutes() {
return Math.floor(this.currentTime / 60);
}
getSeconds() {
return this.currentTime % 60;
}
twoDigitsNumber(value) {
if (value < 10) return `0${value}`;
return `${value}`;
}
stopClick() {
clearInterval(this.intervalId);
}
resetClick() {
this.currentTime = 0;
}
splitClick(min, sec) {
return `${this.twoDigitsNumber(min)}:${this.twoDigitsNumber(sec)}`;
}
// splitClick(min, sec, mil) {
// return `${this.twoDigitsNumber(min)}:${this.twoDigitsNumber(
// sec
// )}:${this.twoDigitsNumber(mil)}`;
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment