javascript does not have a wait() or pause() function. It does have setTimeout() and setInterval() functions. Google those.
The thing is the program doesn't pause. When you call the function to you tell it what to do x milliseconds from now. Javascript continues on with the rest of the script and only after X milliseconds, executes what you told it.
these functions also return a token that you can use to cancel the execution before it happens. These are the clearTimeout() and clearInterval() functions.
This will loop while keep_going is true, and your settimeout will wait 30 seconds to turn it off
var keep_going = true
timeout_token = setTimeout( 'keep_going=false', 30*1000 )
while( keep_going ) {
.... do stuff ...
}
This will execute only once every 30 seconds : however after the fifth time it will cancel itself from running anymore
var interval_token = setInterval( "sayHello()", 30*1000 )
var count = 0
function sayHello()
{
alert("Hello World")
count++
if ( count > 5 ) {
clearInterval(interval_token)
}
}