title: JavaScript function that takes a random argument each time
body: <p>I'm working on a Canvas API game and I want to create some enemies, each time I create a new instance of the enemy I want it to be create in a new position (not randomly, but rather 3 specific positions.</p>
  
  <p>So let's say I have this function:</p>
  
  <pre><code>var enemy = new Enemy(0, Math.random() * 184 + 50, Math.random() * 256);
  </code></pre>
  
  <p>This creates a new enemy with an Y position of 0, an X position which is random and a Speed argument that's also random.</p>
  
  <p>This works fine but I want the enemies to be be created in only 3 specific positons and the speed to only increase by 10 each time new enemy instance is being created.</p>
  
  <p>More info: new enemies are being called once the player get's to the final position of winning, like so:</p>
  
  <pre><code>var increaseDifficulty = function(numEnemies) {
      // remove all previous enemies on canvas
      allEnemies.length = 0;
  
      // load new set of enemies
      for (var i = 0; i &lt;= numEnemies; i++) {
          var enemy = new Enemy(0, Math.random() * 184 + 50, Math.random() * 256);
  
          allEnemies.push(enemy);
      }
  };
  </code></pre>
  
  <p>What I want is a way to create a new enemy with a different argument each time. Only for the position and speed.</p>
  
  <p>Something like:</p>
  
  <pre><code>var enemy = new Enemy(0, 1, 1);
  </code></pre>
  
  <p>The second time it is being called it'll be different so:</p>
  
  <pre><code>var enemy = new Enemy(0, 3, 2);
  </code></pre>
  
  <p>Of course the values won't be 1, 2 and 3 but you get the idea.</p>
  
  <p><strong>UPDATE:</strong> <br>
  The new enemy calls upon this: </p>
  
  <pre><code>var Enemy = function(x, y, speed) {
      this.x = x;
      this.y = y;
      this.speed = speed;
      this.sprite = 'images/enemy-bug.png';
  };
  
  Enemy.prototype.update = function(dt) {
      this.x += this.speed * dt;
      if (this.x &gt;= 505) {
          this.x = 0;
      }
  
      checkCollision(this);
  };
  Enemy.prototype.render = function() {
      ctx.drawImage(Resources.get(this.sprite), this.x, this.y);
  };
  </code></pre>