I know i can use setTimeout but my software has some limitation so I have to use a workaround. I found this online that is supposed to work as a delay function:
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
Because im new to Js i do not know how to call this function. I am trying to do something like this:
sleep(2000) {
...
}
But the above is not working. Can someone please show me how to run the function. Thank you.
Note my question is different because I can't use the setTimeout function.