Password

Task

Create a simple password program.

  1. The user has to enter the password.
  2. Print comments if the password is correct or incorrect.
Solution

Enter the password:




Show Code

Code
function passwordCheck() {
  //get password
  var password = document.getElementById(“passwordBox”);
  var passwordText = password.value;
  //check value
  if(passwordText == “thepassword”) {
  //true
  document.getElementById(“welcome-message”).innerHTML = “Hi there, that was the correct password!”;
  }else{
  //false
  document.getElementById(“welcome-message”).innerHTML = “Access denied! Incorrect password!”;
  }
  }