-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.js
More file actions
27 lines (25 loc) · 766 Bytes
/
Timer.js
File metadata and controls
27 lines (25 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var waitTime = 360000;
var seconds = 0;
var currentSec = 0;
var currentMin = 0;
var currentHour = 0;
var secInterval = 1000;
function WriteTimer(currentHour, currentMin, currentSec){
// Clears the last line
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(`Timer - ${currentHour}:${currentMin}:${currentSec}`);
}
var timer = setInterval(function() {
seconds += secInterval/1000;
currentSec = seconds % 60;
currentMin = Math.floor(seconds/60) % 60;
currentHour = Math.floor(seconds/3600) % 60;
//call function WriteTimer
WriteTimer (currentHour, currentMin, currentSec);
}, secInterval);
setTimeout( function () {
// To clear/stop the timer
clearInterval(timer);
console.log("an hour passed...");
}, waitTime);