What is the use of the Prompt Function in JavaScript ?
The prompt
function in JavaScript is used to interact with the user by displaying a dialog box that allows the user to type input text. It is often used to gather user input simply.
Example: Here, the prompt
function displays a dialog box with the message “Please enter your name:” and an input field. The user can enter text, and the entered value is stored in the userInput
variable. The script then prints a greeting using the entered name.
Javascript
let userInput = prompt( "Please enter your name:" ); console.log( "Hello, " + userInput + "!" ); |
Contact Us