101
rated 0 times
[
105]
[
4]
/ answers: 1 / hits: 5992
/ 8 Years ago, fri, may 13, 2016, 12:00:00
I'm trying to set a timer so it display the seconds and min left of an user and I'm using setInterval
to get the seconds and if there are 60 seconds it will reduce 1 min from the user.
The thing is that I'm getting infinite for
loops every time I try to do it.
Something like
var userObj = {
name: "",
min: 0,
sec:0
}
function timerCount() {
while (userObj.sec !== 0) {
console.log(userObj.min)
if (userObj.sec == 0) {
setInterval(function() {
userObj.min--;
userObj.sec = 59
}, 1000);
}
while(userObj.sec !== 0) {
setInterval(function() {
console.log(userObj.sec)
userObj.sec--;
}, 1000);
}
}
}
More From » jquery