It's Javascript. It's one of the array practice problem on codeHS.
. Write a program that makes a snake with a fixed length move around the screen. The segments should follow the snakehead's path, traveling the exact route that it took . Your snake should move SNAKE_DIM each frame your snake movement will not be as smooth as the demo, but don't worry about that Your Snake must stay on an imaginary grid with grid squares exactly SNAKE_DIM X SNAKE_DIM To do that, you must move SNAKE_DIM every frame Helpful hints Start with a program like basic snake that simply moves a green rectangle (the snake head constantly The snake should start out moving east. When the user presses an arrow key, the snake should change direction to the direction of the arrow o When the snake crosses an edge of the canvas, it should appear at the opposite edge Create an array and fill it with at least 3 more green rectangles that are the same size and color as the snake head o The initial segments should be extended behind the snake o When the snake moves, the segments follow the same path the head took If you get stuck when developing a strategy for making the segments follow the head, here are some options Follow the leader . Going from back to front, tell each segment to move to the position of the next segment Tell the segment behind the head to go to the head Move the head in the current direction Shifty-Push o For this strategy, the you must consider the last item of the array to be the head for the segment just behind the head if the head is separate from the array) o renove the first segment from the array (shift) and add it to the end of the array (push) If the head is separate from the artay, move the item you pushed to the position of the head and then move the head If the head is part of the array, then the head must be the segment you pushed, which means it should be placed at the next position to move to Pop goes to the front of the linel o Th last segment becomes the new head pop the last item off the end of the array and insert it at the front of the arty o Mc e the segment you popped to the next position where the snake should move. Alt math y, the head could be separate from the array, in which case, you would place the segment you popped at the position of the head and then move the head. This would mean the first item in the array is the segment immediately behind the head . For this strategy you might want to investigate the splice function (you can google "javascript splice"), . Write a program that makes a snake with a fixed length move around the screen. The segments should follow the snakehead's path, traveling the exact route that it took . Your snake should move SNAKE_DIM each frame your snake movement will not be as smooth as the demo, but don't worry about that Your Snake must stay on an imaginary grid with grid squares exactly SNAKE_DIM X SNAKE_DIM To do that, you must move SNAKE_DIM every frame Helpful hints Start with a program like basic snake that simply moves a green rectangle (the snake head constantly The snake should start out moving east. When the user presses an arrow key, the snake should change direction to the direction of the arrow o When the snake crosses an edge of the canvas, it should appear at the opposite edge Create an array and fill it with at least 3 more green rectangles that are the same size and color as the snake head o The initial segments should be extended behind the snake o When the snake moves, the segments follow the same path the head took If you get stuck when developing a strategy for making the segments follow the head, here are some options Follow the leader . Going from back to front, tell each segment to move to the position of the next segment Tell the segment behind the head to go to the head Move the head in the current direction Shifty-Push o For this strategy, the you must consider the last item of the array to be the head for the segment just behind the head if the head is separate from the array) o renove the first segment from the array (shift) and add it to the end of the array (push) If the head is separate from the artay, move the item you pushed to the position of the head and then move the head If the head is part of the array, then the head must be the segment you pushed, which means it should be placed at the next position to move to Pop goes to the front of the linel o Th last segment becomes the new head pop the last item off the end of the array and insert it at the front of the arty o Mc e the segment you popped to the next position where the snake should move. Alt math y, the head could be separate from the array, in which case, you would place the segment you popped at the position of the head and then move the head. This would mean the first item in the array is the segment immediately behind the head . For this strategy you might want to investigate the splice function (you can google "javascript splice")