title: JavaScript Array Problems
body: <p>Okay, so I am just going over some basic programming tenets in JavaScript (I am new to programming, so bear with me please). Below is the code I am having issues with (pay particular attention to the string component of the array).</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var name = new Array();
  var sales = new Array();
  var total = prompt("How many total salesmen does your department employ?");
  
  for(i = 0; i &lt; total; i++)
  {
  name[i] = prompt("What is his/her (the salesman's) name?");
  sales[i] = prompt("How much (in dollars) did he/she sell?");
  }
  for(j = 0; j &lt; i; j++)
  {
  document.write(name[j]+" had $"+ sales[j]+" in sales!&lt;br&gt;");
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>As you can see, it's just a simple code to get me familiar with arrays of various types of elements. For some reason, the code returns:</p>
  
  <pre><code>undefined had $100 in sales!
  undefined had $2999 in sales!
  undefined had $4999 in sales!
  undefined had $32342 in sales!
  </code></pre>
  
  <p>which is exactly what I need, except for the fact that each of the elements within the name array is undefined.</p>
  
  <p>I'm thinking it may be an issue with the document.write function, as i've read that it can be dubious but I still don't know exactly how to get this working properly.</p>
  
  <p>Any help would be greatly appreciated!</p>