gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)
- Create function User will enter his Username , Password If username = “admin” and…
- User
- 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
To create the function in HTML and JavaScript using prompt, you can follow the steps below:
- Create an HTML file and add a script tag to include your JavaScript code.
<!DOCTYPE html> <html> <head> <title>Login Form</title> <script src="script.js"></script> </head> <body> <h1>Login Form</h1> <button onclick="login()">Login</button> </body> </html>- Create a JavaScript file (script.js) and write the function to handle the login process.
function login() { var username = prompt("Enter your username:"); var password = prompt("Enter your password:"); if (username === "admin" && password === "421$$") { alert("Welcome! Login success."); } else { var errorMessage = ""; if (username !== "admin") { errorMessage += "Incorrect username. "; } if (password !== "421$$") { errorMessage += "Incorrect password."; } alert(errorMessage); } }In the above code, the
login()function prompts the user to enter their username and password. If the entered username and password match the specified values ("admin" and "421$$"), it displays the success message usingalert(). Otherwise, it generates an error message based on the incorrect input and displays it usingalert().-
Save the JavaScript file as script.js in the same directory as the HTML file.
-
Open the HTML file in a browser, and when the "Login" button is clicked, the prompt will appear to enter the username and password. Based on the entered values, the appropriate message will be displayed.