Learn Dynamic HTML With JS
Lesson 1 - HTML JS Relationship
Lesson 2 - HTML DOM
Lesson 3 - Browser BOM
Lesson 5 - Manipulating CSS
Lesson 6 - HTTP Requests
Lesson 7 - Form Handling
The confirm
method is used to ask the user to confirm or cancel an action, displaying a dialog box with a message and OK
and Cancel
buttons.
let result = confirm("Are you sure you want to exit?"); if (result) { console.log("Action confirmed."); } else { console.log("Action cancelled."); }
Now, let's create a program that takes two inputs from the user (first name and last name) and then displays the complete name.
let firstName = prompt("Enter first name:"); let lastName = prompt("Enter last name:"); alert(firstName + " " + lastName);
Note the usage of two variables, firstName and lastName, with the prompt method to collect user input. The complete name is then displayed using the alert() method.