ivana_andreevska

Clock

Dec 10th, 2021
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function my_Clock() {
  2.     this.cur_date = new Date();
  3.     this.hours = this.cur_date.getHours();
  4.     this.minutes = this.cur_date.getMinutes();
  5.     this.seconds = this.cur_date.getSeconds();
  6. }
  7. my_Clock.prototype.run = function () {
  8.     setInterval(this.update.bind(this), 1000);
  9. };
  10. my_Clock.prototype.update = function () {
  11.     this.updateTime(1);
  12.     console.log(this.hours + ":" + this.minutes + ":" + this.seconds);
  13. };
  14. my_Clock.prototype.updateTime = function (secs) {
  15.     this.seconds+= secs;
  16.     if (this.seconds >= 60) {
  17.         this.minutes++;
  18.         this.seconds= 0;
  19.     }
  20.     if (this.minutes >= 60) {
  21.         this.hours++;
  22.         this.minutes=0;
  23.     }
  24.     if (this.hours >= 24) {
  25.         this.hours = 0;
  26.     }
  27. };
  28. var clock = new my_Clock();
  29. clock.run();
Advertisement
Add Comment
Please, Sign In to add comment