Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. //function is set to false at the beginning
  2. var valid = false
  3. //this is the function
  4. valid = checkPassword(valid)
  5. //if valid is set to true then the message "Password correct" will be alerted. If not then "Password incorrect" will be alerted
  6. if (valid == true) {
  7. alert("Password correct")
  8. } else {
  9. alert("Password incorrect")
  10. }
  11.  
  12. function checkPassword(valid) {
  13. //The variables for the code
  14. var password = ' '
  15. var count = 1
  16.  
  17.  
  18. //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
  19. while (count < 4 && password !== "123XY") {
  20.  
  21. //enter the password
  22. password = prompt("Enter your password please")
  23. //if password is incorrect then try again.
  24. if (password !== "123XY") {
  25. alert("Try again please")
  26. } else {
  27. //return function returns as true
  28. valid = true
  29. return valid
  30.  
  31. }
  32. //each time the password is incorrect the counter will go up by one. Once it reaches 4 then it will stop
  33. count = count + 1
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement