title: Built a login form script but it's not working using JavaScript
body: <p>I am trying to build a login.js script that listens for the login form submit event. When I try to run my code, it's not logging in or working properly</p>
  
  <p>I' working with JavaScript, which is requested to use. I built the login form in HTML and have worked on the login function within JavaScript. It can;t be inline JavaScript, it has to be a separate script from HTML.</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 count = 2;
  
  function validate() {
    var un = document.login.username.value;
    var pw = document.login.password.value;
    var valid = false;
    var usernameArray = ["adrian@tissue.com",
      "dduzen1@live.spcollege.edu",
      "deannaduzen@gmail.com"
    ]
    var passwordArray = ["welcome1", "w3lc0m3", "ch1c@g0"]
    for (var i = 0; i &lt; usernameArray.length; i++) {
      if ((un == usernameArray[i]) &amp;&amp; (pw == passwordArray[i])) {
        valid = true;
        break;
      }
    }
    if (valid) {
      alert("Login is successful");
      window.location = "index.html";
      return false;
    }
    var again = "tries";
    if (count == 1) {
      again = "try"
    }
    if (count &gt;= 1) {
      alert("Wrong username or password")
      count--;
    } else {
      alert("Incorrect username or password, you are now blocked");
      document.login.username.value = "You are now blocked";
      document.login.password.value = "You are now blocked";
      document.login.username.disabled = true;
      document.login.password.disabled = true;
      return false;
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!-- start of login form --&gt;
  &lt;div class="login-page"&gt;
    &lt;div class="form"&gt;
      &lt;form class="register-form" onsubmit="return validate() ;" method="post"&gt;
        &lt;input type="text" placeholder="username" /&gt;
        &lt;input type="text" placeholder="password" /&gt;
        &lt;input type="text" placeholder="email id" /&gt;
        &lt;button&gt;Create&lt;/button&gt;
        &lt;p class="message"&gt;Already registered? &lt;a href="#"&gt;Login&lt;/a&gt;
        &lt;/p&gt;
      &lt;/form&gt;
  
      &lt;form class="login-form"&gt;
        &lt;input type="text" placeholder="username" /&gt;
        &lt;input type="text" placeholder="password" /&gt;
        &lt;button&gt;login&lt;/button&gt;
        &lt;p class="message"&gt;Not registered? &lt;a href="#"&gt;Register&lt;/a&gt;
        &lt;/p&gt;
      &lt;/form&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>It needs to allow the three login information I put into the code to log into the site. When logging in, it blinks as if it's doing something, but isn't going anywhere nor does it show that the person is logged in.</p>