Question
Which JavaScript function is used to get user input from the browser? alert() prompt() console.log() readLine() addEventListener()
Answers
GPT-4o mini
The JavaScript function used to get user input from the browser is `prompt()`. Here’s a brief overview of the options you mentioned:
- `alert()`: Displays a simple alert box with a message but does not capture user input.
- `prompt()`: Opens a dialog box that prompts the user for input and returns the entered value.
- `console.log()`: Outputs messages to the web console, mainly for debugging purposes, and does not interact with the user.
- `readLine()`: This is not a standard JavaScript function for browser input. It may be used in some environments like Node.js for reading input from the terminal.
- `addEventListener()`: This is used to attach an event handler to an element but does not directly capture user input.
Thus, `prompt()` is the correct choice for getting user input from the browser.
- `alert()`: Displays a simple alert box with a message but does not capture user input.
- `prompt()`: Opens a dialog box that prompts the user for input and returns the entered value.
- `console.log()`: Outputs messages to the web console, mainly for debugging purposes, and does not interact with the user.
- `readLine()`: This is not a standard JavaScript function for browser input. It may be used in some environments like Node.js for reading input from the terminal.
- `addEventListener()`: This is used to attach an event handler to an element but does not directly capture user input.
Thus, `prompt()` is the correct choice for getting user input from the browser.