title: I'm trying to generate a random word from my array with a button click
body: <p>So far I get a random word from the list every time I refresh the page, however I want to be able to generate a random word in the <code>textbox</code> with the "show" button. How do I do that? I suppose I should switch out document.write with something else? I've tried <code>onclick</code> instead but it did not work.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var words = [
    'Hello',
    'No',
    'Hi',
    'Banana',
    'Apple'
  ];
  
  function randomWord(words) {
    return words[Math.floor(Math.random() * words.length)];
  }
  
  for (var x = 0; x &lt; 1; x++)
    document.write(randomWord(words));</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form name="f1"&gt;
    &lt;input type="text" value="" name="textbox" id="textbox" /&gt;
    &lt;input type="button" value="show" onclick="randomWord()" /&gt;
    &lt;br/&gt;
  &lt;/form&gt;
  &lt;div id="new" /&gt;</code></pre>
  </div>
  </div>
  </p>