title: Populate a prompt with elements of an array and number them off
body: <p>(Stack Overflow doesn't have a tag for 'prompt' so I have used alert as I am guessing it is similar enough to attract the right answerers.)</p>
  
  <p>Hello,
  I am currently making a JavaScript-based game for an assignment at university. I am usually pretty good with problem solving but have been stumped by this issue.</p>
  
  <p>To explain, I have an array which names the possible armour slots the player can pick. In any order these can be picked, and each time the choice gets pushed to a second array which handles what has already been picked (and in what order) and that item gets spliced from the original array. There is a while loop which runs through until all 3 have been picked. </p>
  
  <pre><code>var armourSlotToPick = ["Head", "Chest", "Legs"],    
      armourSlotPicked = [],
      armourLoop = 1,
      indexArmour = 0;
  
  function numInArray() {
      indexArmour++;
      return (indexArmour + ". " + armourSlotToPick[indexArmour - 1] + "\n");
  }
  
  
  function armour() {
      while (armourLoop &lt; 4) {
          var armourPick = prompt("Pick an armour slot to generate an item for:\n" + armourSlotToPick.forEach(numInArray));
          if (armourPick == 1) {
              armourSlotPicked.push(armourSlotToPick[0]);
              armourSlotToPick.splice(0,1);
          } else if (armourPick == 2) {
              armourSlotPicked.push(armourSlotToPick[1]);
              armourSlotToPick.splice(1,1);
          } else if (armourPick == 3) {
              armourSlotPicked.push(armourSlotToPick[2]);
              armourSlotToPick.splice(2,1);
          } else {
              alert("Invalid choice, you suck");
              break;
          }
          armourLoop++;
      }
  }
  </code></pre>
  
  <p>I know it probably wouldn't be possible to do the whole return in numInArray() to the prompt, but it shows some working. </p>
  
  <p>Now the problem: I got it working so that each item in the array was numbered (var armourSlotToPick = ["1. Head", "2. Chest", "3. Legs"],) but as you could see, if the player chose 2, then the next time it would show "1. Head (new line) 3. Legs" and when the player chooses 3, a problem would occur, as they were really meant to choose 2. How is it possible to number the items in the array, in a prompt?</p>
  
  <p>I'm possibly over thinking this but I have suffered for a few hours now.</p>
  
  <p>I thank you in advance for any insight you may have,</p>
  
  <p>Daniel.</p>
  
  <p><br />
  <strong>EDIT: Solved.</strong></p>
  
  <p>Below is the end result, a slight variation from the edited answer from Jonathan Brooks.</p>
  
  <pre><code>var armourSlotToPick = [null, "Head", "Chest", "Legs"]
  var armourSlotPicked = [null];
  var armourLoop = 1;
  
  function armour() {
      while (armourLoop &lt; 4) {
          var message = "Pick an armour slot to generate an item for:\n";
          for (var i = 0; i &lt; armourSlotToPick.length; i++) {
              if (armourSlotToPick[i] !== null) {
                  message += "" + i + ". " + armourSlotToPick[i] + "\n"; 
              }            
          }
          var armourPick = prompt(message);
          if (armourPick &gt; armourSlotToPick.length-1 || armourPick &lt; 1) {
              alert("Invalid choice, you suck");
          } else {
              var insert = armourSlotToPick.splice(armourPick, 1);
              armourSlotPicked.push(insert);
          }
          armourLoop++;
      }
      armourSlotPicked.splice(0,1);
  }
  
  armour();
  alert(armourSlotPicked.join("\n"));
  </code></pre>
  
  <p>I thank all that have contributed to this discussion and the end result, and I hope this is a good example for future problems people may have similar to this.</p>