我在Node.js中编码Javascript,我有这个功能。
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:")
}
}
问题是我想继续运行usrnew提示符,直到输入的用户名不等于数据库中已有的用户名,我该怎么做?
最佳答案
您可以随时使用while循环:
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: ")
}