title: Javascript: Set variable to either 1 or -1
body: <p>I'm trying to get an object that moves in a different direction when you click on it, and each time you click on it it goes faster. I have it almost functioning, but I can't get the program to exclude 0 or do only -1 or 1; I can only do a random number between -1 and 1. This means that if it hits zero, it can't progress.</p>
  
  <p>(The following code is built with a Javascript engine called "Crafty". Non-javascript parts are commented as best as I can.)</p>
  
  <pre><code>    Crafty.init(400,320, document.getElementById('game')); // Creates canvas
  
      // Create variables
      var speed = 10;
      var min = -1;
      var max = 1;
  
      // Create a 32px by 32px red box
      var square = Crafty.e('2D, Canvas, Color, Mouse, Motion') 
          .attr({x: 50, y: 50, w: 32, h: 32}) 
          .color('red') 
      // When the red box is clicked, move it in a random direction. Make it go faster each time.
          .bind('Click', function(MouseEvent){
              speed *= 2;
              var vel = square.velocity();
              var direction = ((Math.random() * (max - min)) + min);
              vel.x;
              vel.y;
              vel.x = (speed *= direction);
              vel.y = (speed *= direction);
          });
  </code></pre>