Step 11

We must update the Paddle so it does not run off the sides of the canvas.

Add the following method to Paddle.js

handleBoundary(canvasWidth) {
  if (this.x < 0) {
    this.x = 0;
  } else if (this.x + this.width > canvasWidth) {
    this.x = canvasWidth - this.width;
  }
}

Update Paddle.move

move(canvasWidth) {
  super.move(this.dx, 0);
  this.handleBoundary(canvasWidth);
}

Update script.js where it calls paddle.move()

paddle.move(canvas.width);

Save your code again and try it in your browser.