With some guidance from a previous discussion, I've successfully implemented a code that waits for 3000ms and then sets a variable to 1. Subsequently, a loop is triggered every 1000ms to check if the variable has changed, and an alert is displayed when it does.
var myvalue;
setTimeout(function() {
myvalue = 1;
}, 3000);
function check() {
if (myvalue == 1) {
alert("Value Is Set");
} else {
setTimeout(check, 1000);
}
}
alert("debug1");
check();
alert("debug2");
The issue I'm facing now is that the execution doesn't wait for the completion of the check()
function before proceeding. Upon adding some debug alert
s, I noticed that they all fire simultaneously.
Is there a way to make it wait without relying on a timeout?