title: Create an array of buttons from Javascript array
body: <p>I want to create a bunch of buttons in the html body based on an array stored in Javascript. Here is my code:</p>
  <pre><code>&lt;!DOCTYPE&gt;
  &lt;html&gt;
       &lt;head&gt;
             &lt;script&gt;
                  var listBrand =['LEXUS','AUDI','MAYBACK','FERRARI','TOYOTA'];   
                  //the array
                  function printBtn() {
                      for (var i = 0; i &lt; listBrand.length; i++) {
                         var btn = document.createElement(&quot;button&quot;);
                         var t = document.createTextNode(listBrand[i]);
                         btn.appendChild(t);
                         document.body.appendChild(btn);
                      }
                  }
             &lt;/script&gt;  
       &lt;/head&gt;
       &lt;body&gt;
            &lt;div onload=&quot;printBtn();&quot;&gt;
            
            &lt;/div&gt;
       &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>I want to have all 5 buttons <code>LEXUS</code>, <code>AUDI</code>, <code>MAYBACK</code>, <code>FERRARI</code>, and <code>TOYOTA</code> show up in the body when the page loads, but the buttons fail to appear.</p>
  <p>Is there anything wrong with my code? Any help and/or explanations are appreciated. Thank you.</p>