[英]Request for the username and password again if either is wrong
How do i make it so when the password and/or username is wrong it will ask for the password and/or username again? 当密码和/或用户名输入错误时,我将如何再次输入密码和/或用户名?
var user = prompt("Please Enter Your Username To Continue.").toUpperCase();
if (user === "RYEBREAD4") {
var pass = prompt("Please Enter Your Password To Continue").toUpperCase();
if (pass === "7277") {
console.log("Welcome Back Ryebread4");
} else {
console.log("Username Or Password Is Incorrect! Please Try Again");
}
}
Use a while
loop 使用
while
循环
var signedIn = false;
while(!signedIn)
{
...
if (password === "7477")
{
console.log("Welcome back!");
signedIn = true;
}
...
}
Or for
(not recommend) 或
for
(不推荐)
var username = "";
var password = "";
for(;username !== "Ryebread4" && password !== "7477";)
{
//prompt user for username/password
...
}
That same methodology can be applied to the while
loop, and eliminate a variable. 可以将相同的方法应用于
while
循环,并消除变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.