desito07

Login - for loop

May 19th, 2020
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. function login(input) {
  2. let username = input.shift();
  3. let password = username.split("").reverse().join("");
  4.  
  5. let failsCounter = 0;
  6.  
  7. for (let i = 0; i < input.length; i++) {
  8. let currentPassword = input[i];
  9.  
  10. if (currentPassword !== password) {
  11. failsCounter++;
  12. if (failsCounter > 3) {
  13. console.log(`User ${username} blocked!`);
  14. break;
  15. }
  16. console.log(`Incorrect password. Try again.`);
  17. } else {
  18. console.log(`User ${username} logged in.`);
  19. }
  20. }
  21. }
  22. login(["Acer", "login", "go", "let me in", "recA"]);
Add Comment
Please, Sign In to add comment