Hey guys, i'm fairly new to programming in Javascript.
I've been trying to write a basic user name and password program.
I was wondering if I could get some help with how I would put it in a loop so if the information in incorrect, it will prompt up "x" amount of times until the information is correct. Thanks, here's what I have so far.
var user_name = prompt ("Please enter your username: ");
var password = prompt ("Please enter your password: ");
A while loop would be much better than a recursive function:
Code:
while (true) {
var user_name = prompt("Please enter your username: ");
var password = prompt("Please enter your password: ");
if (user_name == "John123" && password == "helloworld") {
alert("Welcome, " + user_name + ".");
break;
}
else {
alert("Sorry, information invalid.");
}
}
This is however a very bad way of coding since it will completely lock the page until the information is correct! You should really use a form with inputs for name and password instead of using prompts.
Bookmarks