gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Ex2; - Create function User will enter his Username , Password If username = “admin” and…
- User
Ex2;
- Create function User will enter his Username , Password If username = “admin” and password = “421$$” Show him message “Welcome login success” If he entered incorrect username or password Tell him which data entered wrong by html and js by prompet
- Assistant
Sure, here's an example of how you can implement this using HTML and JavaScript prompt:
HTML:
<!DOCTYPE html> <html> <head> <title>Login Page</title> <script src="script.js"></script> </head> <body> <h2>Login</h2> <button onclick="login()">Login</button> </body> </html>JavaScript (script.js):
function login() { var username = prompt("Enter username:"); var password = prompt("Enter password:"); if (username === "admin" && password === "421$$") { alert("Welcome login success"); } else { var errorMsg = ""; if (username !== "admin") { errorMsg += "Incorrect username. "; } if (password !== "421$$") { errorMsg += "Incorrect password."; } alert(errorMsg); } }In this example, the code prompts the user to enter their username and password using the
prompt()function. It then checks if the entered username and password match the expected values ("admin" and "421$$"). If they match, an alert with the message "Welcome login success" is shown. If the entered values are incorrect, an error message is generated based on which data was entered wrong (either incorrect username, incorrect password, or both) and shown in an alert.