xxxxxxxxxx
50
let counter = 0;
let timeleft = 60;
let timerId; // task id
function setup() {
noCanvas();
var timer = select("#timer");
timer.html(getFormattedTime(timeleft - counter));
function timeIt() {
counter++;
timer.html(getFormattedTime(timeleft - counter));
if(counter >= timeleft) {
print("hi");
clearInterval(timerId);
}
}
timerId = setInterval(timeIt, 100);
}
function draw() {
noLoop();
}
function getFormattedTime(seconds) {
/*
1 hour = 3600 sec
1 min = 60 sec
*/
let hour = 0;
let min = 0;
let sec = 0;
// hour
hour = floor(seconds / 3600);
seconds %= 3600;
// min
min = floor(seconds / 60);
seconds %= 60;
// sec
sec = seconds;
let timeStr = hour + ":" + min + ":" + sec;
return timeStr;
}