title: Javascript While Looping Through Array And Outputting in .innerhtml
body: <p>I'm brand new to Javascript and teaching myself.  I'm trying to setup a function that will write each of the elements of the array <code>AmericanCars</code> with a space between the elements. </p>
  
  <p>I have it working so that when I use <code>.innerHTML=AmericanCars[Index Position]</code> plus a non-breaking space, I can write one element of the array.  Now I'm trying to loop through it with a <code>while</code> loop, but I just get an output of "undefined."</p>
  
  <p>How can I get <code>.innerHTML</code> to write out each of the elements of an array with a space between them?  Is there a method that is simpler than using the While loop or is my While loop just formatted wrong.</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;script language="javascript" type="text/javascript"&gt;
          var AmericanCars=["Chevy", "Ford", "Dodge"];
          var JapaneseCars=["Honda", "Toyota", "Subaru"];
          var FavoriteCars=[];
  
          function ListAmericanCars() {
  
          var arraycounter = 0; 
  
          /* Use array counter to set the value that is displayed in innerHTML's square [] brackets */
              while (arraycounter &lt;= AmericanCars.length) {
  
                  document.getElementById('content').innerHTML = AmericanCars[arraycounter] + "&amp;nbsp ";
                  arraycounter++;
              }
          }
          &lt;/script&gt;
  
          &lt;p&gt; What Are Your Favorite American Cars?  Answer: 
              &lt;span id="content"&gt;______________
              &lt;/span&gt;
          &lt;/p&gt;
  
          &lt;button onclick="ListAmericanCars()"&gt;
              American Cars Function
          &lt;/button&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>