title: Why isn't my JS code working? I'm trying to get this code to generate a random password
body: <p>EDIT:  Made some changes, now when I click generate password, I get back 'undefined'.  Progress!</p>
  <p>EDIT #2:  Now I am not getting 'undefined' when I click, but devtools says at line 26 i am exceeding maximum call stack.  How do I fix that?</p>
  <p>Javascript is really hard, man. I'm trying to get this code to generate a random password.  When I click the generate password button, nothing happens. Chrome dev tools doesn't show any issues.  I just started learning javascript a week ago.  I need to add more details to post this so...I think I just threw in everything I 'learned' in here, so it's probably really messed up.</p>
  <pre><code>// Assignment code here
  var length;
  var number;
  var specialCharacter;
  var upperCase;
  var lowåerCase;
  var selection;
  var lettersUp
  
  const characters = [&quot;number&quot;, &quot;letters&quot;, &quot;character&quot;];
  
  number = &quot;0123456789&quot;;
  letters = &quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;;
  character = &quot;!@#$%^&amp;*)(&quot;;
  // Get references to the #generate element
  var generateBtn = document.querySelector(&quot;#generate&quot;);
  // Write password to the #password input
  function writePassword() {
    var password = generatePassword();
    var passwordText = document.querySelector(&quot;#password&quot;);
  
    passwordText.value = password;
  }
  // Begin setting password parameters
  function generatePassword() {
    document.getElementById(&quot;click&quot;, generatePassword); {
      for ( let i = 0; i &lt; length; i++ ) {
        console.log(password);
      }
    }
  
    // Select # of characters for new password
    length = prompt(&quot;Enter the number of characters you'd like for your new password (Select a number between 8-128)&quot;);
    if (!length) {
      alert(&quot;Please make a valid entry&quot;);
    } else if (length &lt; 8 || length &gt; 128) {
      // Function recognizes incorrect input
      length = prompt(&quot;New password must be from 8-128 characters&quot;);
    } else {
      // Prompts continue when length input is valid
      number = confirm(&quot;Include numbers in your new password?&quot;);
      specialCharacter = confirm(&quot;Include special characters in your new password?&quot;);
      upperCase = confirm(&quot;Include uppercase letters?&quot;);
      lowerCase = confirm(&quot;Include lowercase letters?&quot;);
    };
    // for all of the above true
    if (number &amp;&amp; specialCharacter &amp;&amp; upperCase &amp;&amp; lowerCase) {
      selection = character.concat(number,letters,lettersUp);
    }
    // three options selected
    else if (number &amp;&amp; specialCharacter &amp;&amp; upperCase) {
      selection = character.concat(number, lettersUp);
    }
    else if (specialCharacter &amp;&amp; upperCase &amp;&amp; lowerCase) {
      selection = character.concat(letters, lettersUp);
    }
    else if (upperCase &amp;&amp; lowerCase &amp;&amp; number) {
      selection = lettersUp.concat(letters, number);
    }
    else if (lowerCase &amp;&amp; number &amp;&amp; specialCharacter) {
      selection = letters.concat(number, character);
    }
    //two options selected
    else if (specialCharacter &amp;&amp; number) {
      selection = character.concat(number);
    }
    else if (number &amp;&amp; upperCase) {
      selection = number.concat(lettersUp);
    }
    else if (upperCase &amp;&amp; lowerCase) {
      selection = lettersUp.concat(letters);
    }
    else if (lowerCase &amp;&amp; number) {
      selection = letters.concat(number);
    }
    else if (lowerCase &amp;&amp; specialCharacter) {
      selection = letters.concat(character);
    }
    else if (specialCharacter &amp;&amp; upperCase) {
      selection = character.concat(lettersUp);
    }
    //one option
    else if (specialCharacter) {
      selection = character;
    }
    else if (number) {
      selection = number;
    }
    else if (lowerCase) {
      selection = letters;
    }
    else if (upperCase) {
      selection = lettersUp;
    };
  
    
  }
  
  generatePassword();
  
  // Add event listener to generate button
  generateBtn.addEventListener(&quot;click&quot;, writePassword);
  </code></pre>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot; /&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;
      &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot; /&gt;
      &lt;title&gt;Password Generator&lt;/title&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;./assets/css/style.css&quot; /&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div class=&quot;wrapper&quot;&gt;
      &lt;header&gt;
        &lt;h1&gt;Password Generator&lt;/h1&gt;
      &lt;/header&gt;
      &lt;div class=&quot;card&quot;&gt;
        &lt;div class=&quot;card-header&quot;&gt;
          &lt;h2&gt;Generate a Password&lt;/h2&gt;
        &lt;/div&gt;
        &lt;div class=&quot;card-body&quot;&gt;
          &lt;textarea
            readonly
            id=&quot;password&quot;
            placeholder=&quot;Your Secure Password&quot;
            aria-label=&quot;Generated Password&quot;
          &gt;&lt;/textarea&gt;
        &lt;/div&gt;
        &lt;div class=&quot;card-footer&quot;&gt;
          &lt;button id=&quot;generate&quot; class=&quot;btn&quot;&gt;Generate Password&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;script src=&quot;./assets/js/script.js&quot;&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>