Reputation: 291
I am coding Javascript in Node.js, I have this function.
function addaccountfunc(usrnew, passnew) {
console.log(" Forgotten passwords/usernames can NOT be reset!")
if (usrnew === usr ){
console.log("Sorry, that username is taken, would you like to chose another?")
}
var usrnew = prompt("Chose a username: ")
if (passnew != password){
var passnew = prompt("Chose a password:")
}
}
The problem is I would like to keep re running the usrnew prompt, until a username is entered that does not equal something already in the database, how would I go about doing this?
Upvotes: 0
Views: 69
Reputation: 179
You can always use a while loop:
var usrnew = prompt("Choose a username: ")
while(usrnew === usr) {
console.log("Sorry, that username is taken, would you like to choose another?")
var usrnew = prompt("Choose a username: ")
}
Upvotes: 2