+ 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; } } }
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"];
+ 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.
+ 1
Thank you for your assistance! I am moving closer toward a concrete answer.