Code skill Eating the Fruit

This piece of code applies collision detection to the fruit, using a loop to check whether the location of the snake matches the location of the fruit. If they do match, then you use the splice method to remove the fruit from the board and the unshift method to make the snake grow. You will also use the increment operator to count the score (how many fruits are eaten).

See the Pen GB10 M2 by Walker Books UK (@walkerbooks) on CodePen.