Thread: Looping help.
View Single Post
Old 01-11-2013, 08:21 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,549
Thanks: 62
Thanked 4,054 Times in 4,023 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Missing a final } at the very end of the code, to close the for loop.

And the message "You've used up all your attempts." will *NEVER* be seen.

That's because it is only seen (a) INSIDE the for loop and (b) when i is 2 or greater. But i can never be 2 or greater inside that loop, by the very terms of how the for is written.

Try again?
Code:
var user_name, password, passed = false;
for(var i=1; i<= 3 && passed == false; i++)
{
    user_name = prompt ("Please enter your username: ");
    password = prompt ("Please enter your password: ");

    passed = ( (user_name=="John123") && (password= "helloworld") );
} // end of loop after 3 tries *OR* if passed is true!

if ( passed )
{
    alert("Welcome, " + user_name + ".");
} else {
    location.href = "http://www.google.com";
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Users who have thanked Old Pedant for this post:
diceman93 (01-11-2013)