Help on snake game

I am creating a snake game in javascript. I have been placing the snake randomly every time and started moving the snake somehow. My first question is how should I approach moving the snake array automatically in a direction. And is how the function to move the snake around and how to improve it to allow the snake to keep moving in the key pressed unless a different key is pressed? Code:

2 posts were merged into an existing topic: Struggling with snake game