Task
Create a simple password program.
- The user has to enter the password.
- Print comments if the password is correct or incorrect.
Solution
Enter the password:
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!”; | |
| } | |
| } |


