var direction;
function movement(){
switch(direction){
case 1: positionX = positionX + 10;
break;
case 2: positionX = positionX - 10;
break;
case 3: positionY = positionY - 10;
break;
case 4: positionY = positionY + 10;
break;
}
snake.style.marginLeft = positionX + "px";
snake.style.marginTop = positionY + "px";
}
function changeDirection(a){
direction = a;
}
setInterval(movement(), 500);
I don't know why setInterval doesn't work. I tried only writing "funcName", funcName, funcName() and putting the function in a var but it doesn't work.