Laser Locker

4. Login

Now it’s time to login. When the button is clicked, we need to loop through the username list to see if the username that was entered in the textInput box matches any username that is in our list. If we can match the username to one of the accounts in the username list, then we need to check to make sure that the password in the textInput box matches the parallel password in the passwords list. If both the username and password match, then we can move to screen 2. If they do not, then we should display to the user the error, and clear out the input boxes.

When you think about looping through the list think about the fact that no matter how many user accounts there are, we can always know how long the list is. If we loop for that length, then we will be able to check the entered username to every username that is in the list. Since the usernames and passwords lists are parallel we know if we found the username at index 4, the password would have to match the password at index 4 as well.
Hint

Remember that:

var i = 0;
list[i];
would be searching the index 0 of list. Remember too that loops end up incrementing a variable by 1 each iteration.
Next
Back