1

I want to do this

statement1;
// rest for 0.5 seconds
statement2;

How can I make my JavaScript wait 0.5 seconds?

I tried

statement1;
window.setTimer(500);
statement2;

But that was not it. Thanks

Heavy Rain
  • 57
  • 1
  • 1
  • 4
  • 3
    Use setTimeout, look it up. – Etheryte Aug 09 '14 at 17:32
  • Well, `window.setTimer` doesn't exist, so it's not that surprising that it didn't work. Before you try anything, read the documentation of the function you are trying to call. If you can't find documentation than the function might not exist. – Felix Kling Aug 09 '14 at 17:36

2 Answers2

7
statement1();
setTimeout(function() {
    statement2();
}, 500);
John Sterling
  • 1,091
  • 7
  • 13
2

You can put a timer like this statement1();

setTimeout(
  function() 
  {
        statement2();
  }, 500);

How to wait 5 seconds with jQuery?

Community
  • 1
  • 1
EdwardB
  • 76
  • 1
  • 6