title: How to confirm two passwords are equal in JavaScript
body: <p>I'm trying to make a simple password confirmer work in JS. Basically the user has 2 input fields, and if they match nothing happens, but if they dont match then there will be an alert window</p>
  
  <p>This is also my first day doing javascript, and also my first question on Stack Overflow, apologies for any errors or mishaps. Thank You</p>
  
  <pre><code>&lt;body&gt;
      &lt;form&gt;
          Password:&lt;br&gt;
          &lt;input type="password" name="password" placeholder="Password"&gt;
          &lt;br&gt;
          Re-enter Password:&lt;br&gt;
          &lt;input type="password" name="confirmPassword" placeholder="Confirm password"&gt;
          &lt;br&gt;
          &lt;input type="submit" onclick="ansValidation()" value="Sign Up"&gt;
      &lt;/form&gt;
      &lt;br&gt;
      &lt;script&gt;
          function ansValidation() {
              var nameValue = document.getElementById("name")
              var passValue = document.getElementById("password")
              var confpassValue = document.getElementById("confirmPassword")
              if(typeof nameValue != String){
                  window.alert("Please re-enter your name")
              }else if(passValue != confpassValue) {
                 window.alert("Passwords do not match!")
              }
          }
      &lt;/script&gt;
  &lt;/body&gt;
  
  </code></pre>