I'm trying to make a recursive loop using SetTimeout, but when I call the wait() method it doesn't wait for the loop to finish to return true, and since it doesn't return true it falls to else because it didn't find the expected value.
The wait() function is executed, but does not wait for the loop to terminate.
The number 100 represents speed, and the number 10 represents the amount of iteration I want to happen.
EDIT: I'm using internet explorer, and Promise doesn't work for me
function wait(time, limit) {
if (limit < 0) return true
setTimeout(function () {
wait(time, --limit)
}, time);
}
if (wait(100, 10)) {
console.log('success')
} else {
console.log('error')
}
How to wait for the loop to be finished and then fall to the IF?