STDIO Training

45 bundles
1 file6 months ago
3

DigitalClock

DigitalClock.js

12345678910111213141516171819202122232425262728293031323334class DigitalClock {
  constructor() {
    this.hours;
    this.minutes;
    this.seconds;
    this.clock;

    this.startTime = 0;
  }

  start() {
    this.clock = setInterval(() => {
      this.update();
      this.show();
    }, 1000);
  }

  stop() {
    clearInterval(this.clock);
  }

  update() {
    let now = new Date();
    this.hours = now.getHours();
    this.minutes = now.getMinutes();
    this.seconds = now.getSeconds();
  }

  show() {
    console.log(this.hours + ":" + this.minutes + ":" + this.seconds);
  }
}

export { DigitalClock };