gpt4 book ai didi

javascript - 为什么这段代码不起作用? for 和 if 的组合用于 "test"登录页面

转载 作者:行者123 更新时间:2023-12-03 02:55:07 24 4
gpt4 key购买 nike

我正在尝试制作某种登录页面(我不关心安全性或某种类型。这是一个测试,我什至不是那么高级的编码员。而且我正在努力解决编码。我想将其设为:

    If the username was filled in as "Ardent" and the password as "1", 
Say something like "Welcome!"
If the username or(and) the password are(is) incorrect,
alert("The username and password is incorrect.");
and make it loop, leading to asking for username and password again.

所以,这就是我编码的内容(我不知道它是如何工作的,所以我什至不知道它的基本结构)。

for([id == prompt("What is your ID?"), password == prompt("What is your password?")]; 
id == "Ardent" || password == "1" ;) {

prompt("What is your ID?");
prompt("What is your password?");
if(id == "Ardent" || password == "1") {
alert("Welcome back!");
}
}

谢谢!抱歉,如果它实际上是一团糟:(我的编码能力很差,而且我只是个初学者。

最佳答案

您可以从下面非常清晰的代码开始。

while(true){
var username = prompt("What is your username");
var password = prompt("What is your password");

if(username == "Ardent" && password == "1"){
alert("Welcome");
break;
}
else{
alert("Try again");
}
}

希望有帮助。

关于javascript - 为什么这段代码不起作用? for 和 if 的组合用于 "test"登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47666881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com