I am creating a team in JS to count the time the user will take to complete the task. I am using setInterval()
to run the team but I am not able to increment to more than (1) the value of min()
. This is my code:
const time = {
min: 0,
sec: 0,
getSec: function(){
this.sec++;
if (this.sec === 59) {
this.min=+1;
this.sec =0;
}else {
if (this.sec >= 59) {
this.sec = '00';
this.min=+1;
}
}
},
}
$sT = $('.score-panel').find('#time');
function setTime () {
setInterval(function(){
time.getSec();
$sT.html(time.min + ':' + time.sec);
},1000)
}
window.clearInterval(setTime());
if
within else
was an attempt to increment the minutes as the second gives 59.
The window.clearInterval()
is to stop the time when the user changes screen.