Code skill The AI Paddle

We need a simple piece of AI that will make the computer try to position the middle of its paddle at the same X coordinate as the ball. Because the paddles move at a fixed speed and the ball speeds up as it bounces, the computer won’t always be able to reposition the paddle in time. Add the AI at the end of the updateGame function and use a simple calculation and if statement to make it work.

See the Pen GB8 M3 by Walker Books UK (@walkerbooks) on CodePen.