mihalkoff

Login task

Jan 18th, 2021
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let username = input[0];
  3.     let password = '';
  4.  
  5.     //reverse username
  6.     for(let i = username.length - 1; i >= 0; i--) {
  7.         password += username[i];
  8.     }
  9.  
  10.     //check password
  11.     for(let i = 1; i < input.length; i++) {
  12.         if(i < 4) {
  13.             if(password === input[i]) {
  14.                 console.log(`User ${username} logged in.`);
  15.             } else {
  16.                 console.log("Incorrect password. Try again.");
  17.             }
  18.         } else if(i == 4) {
  19.             if(password === input[i]) {
  20.                 console.log(`User ${username} logged in.`);
  21.             } else {
  22.                 console.log(`User ${username} blocked!`);
  23.             }
  24.         }  
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment