What is wrong with this user login code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is wrong with this user login code?

var users = [ "Rose", "Imahni" ]; var passes = [ "geORG20", "rubiCKSbUBBB33" ]; var user=prompt("Enter Username: ", " "); var pass=prompt("Enter Password: ", " "); for (var x=0; x<users.length;x++){ if (user === users[x] && pass === passes[x]){ alert("Welcome!"); return true; } else { alert("Invalid Log-In"); return false; } }

17th Apr 2020, 7:23 AM
Imahni King-Murillo
Imahni King-Murillo - avatar
2 Answers
+ 2
I was able to get it at working at least halfway: https://code.sololearn.com/W2Tp5U8soLJ8/?ref=app So, now it will say “Welcome” if you enter the correct info. and then it says “invalid...”. I’m mot sure y the second one is popping up.
17th Apr 2020, 7:46 AM
Ginfio
Ginfio - avatar
+ 2
Thank you very much! I think I understand what I did wrong. I believe the counter is forcing the for loop to run once more and test the input through the if statement. Therefore, though the input may be valid the first time around, it isn’t the second. Correct me if I am wrong. I understand this is a very bad method of log-in verification, but I am trying to start somewhere. Any and all comments/advice will be of great service to me. Once again, thank you!
17th Apr 2020, 7:51 AM
Imahni King-Murillo
Imahni King-Murillo - avatar