function test() {
let counter = 0;
var bool = false;
const i = setInterval(function(){
console.log(counter);
counter++;
if(counter === 5) {
bool = true;
clearInterval(i);
}
}, 200);
return bool;
}
if (test() == true) {
console.log(true);
} else {
console.log(false);
}
Output
false
0
1
2
3
4
What i want it to do
0
1
2
3
4
true