title: Creating player boundaries in Javascript
body: <p>I am currently facing an issue where without setting boundaries my player or otherwise referred to as cannon is allowed to move off the screen. I have tried implementing some boundaries but I am unable to figure out the logic and it currently does not work.</p>
  
  <p>To clarify I'm looking to make it so once the cannon reaches the wall on either side (It can only move left to right) it is not allowed to exceed the boundaries of the game.</p>
  
  <p>my current boundaries function.</p>
  
  <pre><code>function playerBounds() {
      //This will check the position of the spaceship and if it hits the boundaries of the canvas will not let it go further.
  
      if (spaceShip.x &lt; 0) {
          spaceShip.x = 0;
      }
      else if (spaceShip.x &gt; canvas.width || spaceShip.x &lt; canvas.width  ) {
          spaceship.x = canvas.wdith - spaceShip.width;
      }
  
  }
  </code></pre>