Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //function is set to false at the beginning
- var valid = false
- //this is the function
- valid = checkPassword(valid)
- //if valid is set to true then the message "Password correct" will be alerted. If not then "Password incorrect" will be alerted
- if (valid == true) {
- alert("Password correct")
- } else {
- alert("Password incorrect")
- }
- function checkPassword(valid) {
- //The variables for the code
- var password = ' '
- var count = 1
- //code will loop until both conditions have been met: both password needs to be correct and the password needs to be correct within 3 guesses
- while (count < 4 && password !== "123XY") {
- //enter the password
- password = prompt("Enter your password please")
- //if password is incorrect then try again.
- if (password !== "123XY") {
- alert("Try again please")
- } else {
- //return function returns as true
- valid = true
- return valid
- }
- //each time the password is incorrect the counter will go up by one. Once it reaches 4 then it will stop
- count = count + 1
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement