I would like to be able to make something similar to this:
function testFunction() {
alert("Test");
}
if (x > y) {
wait(z);
testFunction();
}
Thanks!
I would like to be able to make something similar to this:
function testFunction() {
alert("Test");
}
if (x > y) {
wait(z);
testFunction();
}
Thanks!
Can now nicely be done with promises:
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function demo() {
console.log('Taking a break...');
await sleep(2000);
console.log('Two second later');
}
demo();
Please try using the setTimeout function:
setTimeout(function(){ alert("Hello"); }, 3000);
From this link:
https://www.w3schools.com/jsref/met_win_settimeout.asp
So for your specific use case:
var timeToWait = 3000; // in miliseconds.
function testFunction() {
alert("Test");
}
if (x > y) {
setTimeout(function(){ testFunction(); }, timeToWait);
}
Hope that helps.
You have to put your code in the callback function you supply to setTimeout:
function stateChange(newState) {
setTimeout(function () {
if (newState == -1) {
alert('VIDEO HAS STOPPED');
}
}, 5000);
}
From this question: Javascript - Wait 5 seconds before executing next line