Answer the question
In order to leave comments, you need to log in
js event timer?
tell me how to organize a simple cycle?
while (hlt1 > 0 && hlt2 > 0)
{
setTimeout(function () {
hlt1 -= atk2;
hlt2 -= atk1;
console.log(hlt1, hlt2)
}, 1000);
}
Answer the question
In order to leave comments, you need to log in
while
not needed here. You need to do this: jsfiddle.net/7m6waxLm
var hlt1 = 10,
hlt2 = 10;
function change() {
hlt1 -= 1;
hlt2 -= 1;
var inProgress = hlt1 > 0 && hlt2 > 0;
console.log(hlt1, hlt2, inProgress);
if (inProgress) {
setTimeout(change, 1000);
}
}
setTimeout(change, 1000);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question