+ 1

Can someone please explain to me what I did wrong in this Javascript 'Sign-In' code?

function val() { var user = prompt("Enter Username", " "); var pass = prompt("Enter Password", " "); var users[2] = { "Rose", "Imahni" }; var passes[2] = { "galaxymom", "JUMPERgogo" }; for (var x = 0; x < users.length; x++) { if (user == users[x]) { return true; } else { return false; } } for (var i = 0; i < passes.length; i++) { if (pass == passes[x]) { return true; } else { return false; } } }

17th Apr 2020, 2:07 AM
Imahni King-Murillo
Imahni King-Murillo - avatar
3 odpowiedzi
+ 6
Imahni King-Murillo if you're defining users in object then you have to define object with keys var users = { user1: "Rose", user2: "Imahni" }; if you're are defining array then remove braces and add brackets [ ] var users = ["Rose", "Imahni"];
17th Apr 2020, 2:29 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 2
1. Use triple equals to compare. 2. According to your logic, user can enter either username or pass correct and it will return true, there is no condition that both of them should be true.
17th Apr 2020, 3:10 AM
Arvind Singh Rawat
Arvind Singh Rawat - avatar
+ 1
Thank you for your assistance! I am moving closer toward a concrete answer.
17th Apr 2020, 7:22 AM
Imahni King-Murillo
Imahni King-Murillo - avatar