function doKeyDown(event) { switch (event.keyCode) { case 32: /* Space bar was pressed */ if (x == 4) { setInterval(drawAll, 20);
clearInterval is one option:
var interval = setInterval(doStuff, 2000); // 2000 ms = start after 2sec function doStuff() { alert('this is a 2 second warning'); clearInterval(interval); }