desito07

Login - while loop

May 18th, 2020
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 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. let currentPassword = input.shift();
  7. while (currentPassword !== password && failsCounter < 3) {
  8. failsCounter++;
  9. console.log(`Incorrect password. Try again.`);
  10. currentPassword = input.shift();
  11. }
  12. if (currentPassword === password) {
  13. console.log(`User ${username} logged in.`);
  14. } else {
  15. console.log(`User ${username} blocked!`);
  16. }
  17. }
  18. login(["Acer", "login", "go", "let me in", "recA"]);
  19. login(["momo", "omom"]);
  20. login(["sunny", "rainy", "cloudy", "sunny", "not sunny"]);
Add Comment
Please, Sign In to add comment