function doKeyDown(event) {
switch (event.keyCode) {
case 32:
/* Space bar was pressed */
if (x == 4) {
setInterval(drawAll, 20);
Side note – if you want to use separate functions to set & clear interval, the interval variable have to be accessible for all of them, in 'relative global', or 'one level up' scope:
var interval = null;
function startStuff(func, time) {
interval = setInterval(func, time);
}
function stopStuff() {
clearInterval(interval);
}