title: Pause Canvas game with boolean
body: <p>I'm creating a HTML5 Canvas game, if the P, key is pressed (keycode 80) the game will pause. If the key is pressed a second time, the game  will continue. Is there an easy way to toggle the isPaused boolean every time the P key is pressed? Here is my code thus far:</p>
  
  <pre><code>    var isPaused = false;   
  
    function checkKey(e, value) {
    var keyID = e.keyCode || e.which;
  
    if (keyID === 38) { // Up arrow
      player1.isUpKey = value;
      e.preventDefault();
    }
    if (keyID === 80) { 
      isPaused = !isPaused; 
  }
  
  }
  </code></pre>
  
  <p>// game loop </p>
  
  <pre><code>    function step() {
        setTimeout(function() {
  
          if (!isPaused) {  
            update();  // controls character movement
          }  
  
    draw();
      requestAnimFrame(step);
    }, 30); 
  }
  </code></pre>
  
  <p>Many thanks, </p>