SetInterval movement problems. Unclear on how it works

Hello! I’m currently trying to implement automatic movment to my recreation of the google Snake game. I’m learning about setInterval, and i’m not sure why the movement for the snake is automatic in one direction, but when you click another key the movement still keeps the previous direction while mpving in the new direction. It sounds weird but if you test it out you’ll see what i mean. So yeah, i just need help maming the movement only move in the new direction on a new keypress.

The demo is not working for me