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 am facing an issue with the setInterval function not working as expected in my JavaScript code. I have tried different ways to call the function including writing just the function name, using funcName, and funcName() but none seem to make it work.