Need to make a function wait for 4 seconds before returning a string, but not having any luck. Basically this is what I'm trying to do:
function myFunction(){
var str = '';
// DO SOMEHITNG HERE so when it's done the finally return "I'm done"
return "I'm done";
}
This is what I currently have (What am I missing), but I'm also down for any other way to do this. Thanks in advance!
function myFunction(){
var counter = 0;
var execute = setInterval(print, 1000);
function print(){
document.write("Counting" + counter + "<br/>");
++counter;
if(counter < 5){
clearInterval(execute);
str = "I'm done";
}
}
return str; // Here I want to return "I'm done"
}