title: Appending JS array to a variable and displaying it?
body: <p>Im trying to make a weird online program but im having trouble.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>        function name() {
          var titles = ["titles", "titles", "titles", "titles", "titles", "titles"];
          var randFor = Math.random();
          randFor = 7 * randFor;
          randFor = Math.floor(randFor);
  
          var finished = [];
          var arraySpot = 0;
          var newVal;
          var newValSpot = 0;
          newVal = finished[newValSpot];
          for (i = 0; i &lt; randFor; i++) { 
              var randArray = Math.random();
              randArray = 7 * randArray;
              randArray = Math.floor(randArray);
  
              finished.push[arraySpot] = titles[randArray];
  
              arraySpot++;
              newValSpot++;
              newVal = " " + finished[newValSpot];
          }
  
          document.getElementById("gen").innerHTML =newVal;
  
      }
  </code></pre>
  
  <p>Basically, what im trying to do is take an array of words, and convert it to a variable and display it in this tag:</p>
  
  <pre><code>&lt;div id="gen"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>But every time it gives me "undefined" with a space in front of it?</p>
  
  <p>Any help is appreciated, sorry for being such a noob in JS.</p>
  
  <p><em>UPDATE</em>
  I have revised the code, i no longer get "undefined" but now i get nothing?</p>
  
  <pre><code>        function name() {
          var titles = ["titles", "titles", "titles", "titles", "titles", "titles"];
          var randFor = Math.random();
          randFor = 7 * randFor;
          randFor = Math.floor(randFor);
  
          var newVal;
          newVal = title[0];
          for (i = 0; i &lt; randFor; i++) { 
              var randArray = Math.random();
              randArray = 7 * randArray;
              randArray = Math.floor(randArray);
  
              newVal = " " + titles[randArray];
          }
  
          document.getElementById("gen").innerHTML = newVal;
  
      }
  </code></pre>