title: Random Letter Generator
body: <p>I'm a total newb here learning how to code :)
  Hoping someone can shed some light on the following.</p>
  <p>I'm writing some code in JavaScript to generate a random mix of 6 letters from the alphabet using a Math.random method and a for-loop.</p>
  <p>I can get this to work when I write the code 'Math.floor(Math.random() * alphabet.length)' directly into the array index however when I assign it to a variable and use that as the index instead, I end up with a 'random' letter that's duplicated 6 times.</p>
  <p>Is it possible to assign a random value (using the Math.random method) to a variable and have it execute each time it goes through the loop?
  Thanks in advance!</p>
  <p><strong>This is the code that works:</strong></p>
  <pre><code>var alphabet = &quot;abcdefghijklmnopqrstuvwxyz&quot;;
  var randomString = &quot;&quot;;
  
  for (var i = 0; i &lt; 6; i++) {
  randomString += alphabet[Math.floor(Math.random() * alphabet.length)];
  
  console.log(randomString);
  }
  </code></pre>
  <p>Output code example: xuhmwg</p>
  <p><strong>This code ends up with duplicated letters:</strong></p>
  <pre><code>var alphabet = &quot;abcdefghijklmnopqrstuvwxyz&quot;;
  var randomString = &quot;&quot;;
  var randomNumber = Math.floor(Math.random() * alphabet.length);
  
  for (var i = 0; i &lt; 6; i++) {
  randomString += alphabet[randomNumber];
  
  console.log(randomString);
  }
  </code></pre>
  <p>Output code example: dddddd</p>