setTimeout starts a separate execution "thread" within the JavaScript interpreter. You need to pass it a function and design your scripts in such a way that the function the setTimeout runs will continue where the calling function left off--thereby simulating a sleep.