title: JAVASCRIPT - how to make a function that works when a wrong password is entered thrice?
body: <p>Doing this for a school project. Our task is to make a working log-in form without a server. I'm done with most of it, but there's one more requirement for the form. Using only HTML, Javascript, and CSS.</p>
  
  <p>The requirement is that when the user inputs the incorrect username/password three times, there should be an alert that appears and locks the page.</p>
  
  <p>Please help?</p>
  
  <p>This is my code so far: </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>function enterUsername() {
      var x = document.forms["myForm"]["fname"].value;
      if (x == "") {
       alert("Name must be filled out");
    return false;
   }
  }
          
  function inputPass() {
      var x = document.forms["myForm"]["pword"].value;
      if (x == "") {
       alert("Password must be filled out");
    return false;
   }
  }
      
  function enterPassword() {
    var password = document.getElementById("pword").value;
    var username = document.getElementById("fname").value;
    if (password == "hello" &amp;&amp; username == "1234") {
     window.location = "project mainframe.html";
     return true; 
     }
    else if (password !== "hello" &amp;&amp; username !== "1234") {
     alert("Either Username or Password is incorrect");
     return false;
   }
  }
       
  function timeAlert() {
     alert("Your time limit has run out." + "\n" + "Please refresh the page to try again.");
     window.location = "project.html"
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body{
   background: url("backgroundimg.jpg");
   background-size: cover;
   background-repeat: no-repeat;
   background-position: center center;
   }
   
  div.login {
  border: none;
  border-left: 1px;
  }
   
  input[type=text], select {
   width: 100%;
   padding: 14px 20px;
   margin: 8px 0;
   display: inline-block;
   border: 1px solid #ccc;
   border-radius: 4px;
   box-sizing: border-box;
  }
  
  input[type=password], select {
   width: 100%;
   padding: 14px 20px;
   margin: 8px 0;
   display: inline-block;
   border: 1px solid #ccc;
   border-radius: 4px;
   box-sizing: border-box;
  }
  input[type=submit] {
   width: 40%;
   background-color: #1a1aff;
   color: white;
   padding: 14px 20px;
   margin: 8px 0;
   border: none;
   border-radius: 4px;
   cursor: pointer;
  }
  
  input[type=submit]:hover {
   background-color: #0000e6;
  }
  
  input[type=reset] {
   width: 40%;
   background-color: red;
   color: white;
   padding: 14px 20px;
   margin: 8px 0;
   border: none;
   border-radius: 4px;
   cursor: pointer;
  }
  
  input[type=reset]:hover {
   background-color: #e60000;
  }
  div.inner {
   background-color: #f1f3f2;
   padding: 20px;
   width: 470px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
    &lt;head&gt;
     &lt;title&gt;Log In Form &lt;/title&gt;
    &lt;/head&gt;
            
    &lt;body onload="setTimeout(timeAlert, 6000)"&gt;
      &lt;center&gt;
      &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt; 
            
      &lt;div class=inner&gt;
      &lt;div class=border&gt;
    &lt;div class=login align=left&gt;
    &lt;font size=13 face=helvetica&gt; Log In &lt;/font&gt;&lt;br&gt;
    &lt;form name="myForm"&gt;
    &lt;font face=helvetica size=6&gt;
    &lt;input type="text" placeholder="Username" id="fname" size=30 name="fname" required/&gt; 
    &lt;input type="password" placeholder="Password" id="pword" name="pword" required/&gt; &lt;br&gt;
    &lt;input type=submit onClick="enterUsername(),inputPass(),enterPassword(); return false" id="button" value="OK"/&gt; 
    &lt;input type=reset value="CANCEL"/&gt;
    &lt;/form&gt; 
      &lt;/div&gt;
      &lt;/div&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>