WEB-DEVELOPMENT-APPLICATIONS practice question 6 of 25
Which method allows the end user to enter text as an answer to a question as the page loads?
Full set: 131 questionsThe window.prompt() method displays a dialog box with an optional message that prompts the user to input text. It is a built-in browser method that provides a simple way to get text input from a user. The method returns the string of text entered by the user, or the value null if the user cancels the dialog.
A. Write: The document.write() method writes HTML expressions or JavaScript code to a document; it does not solicit user input.
B. Confirm: The window.confirm() method displays a dialog with a message and OK/Cancel buttons, returning a boolean value, not text.
D. alert: The window.alert() method displays a dialog box with a message and an OK button to communicate information to the user, not to receive input.
1. Mozilla Developer Network (MDN). window.prompt(). "The window.prompt() method displays a dialog with an optional message prompting the user to input some text." Retrieved from https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt
2. WHATWG. HTML Living Standard. Section 8.1.5.3, "Simple dialogs," defines the behavior of alert, confirm, and prompt. Retrieved from https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#simple-dialogs
3. Flanagan, D. (2020). JavaScript: The Definitive Guide (7th ed.). O'Reilly Media. Chapter 15, "The Window Object," section on "Dialog Boxes."
Question breakdown
Key idea: window.prompt() displays a dialog with a text field and returns the text the user entered, or null if the user cancels.
How to reach the answer
- The clue is that the user must 'enter text as an answer to a question'.
- alert only displays a message.
- confirm returns true or false from the OK and Cancel buttons.
- document.write outputs content and takes no input.
- prompt is the only option that collects typed text.
Each option
Common trap: confirm is tempting because it also asks the user a question, but it only produces a yes/no boolean.
In practice: prompt is used in quick demos, learning exercises, and debugging. Production sites usually build forms or custom modals instead.
Remember: alert shows a message, confirm asks yes/no, and prompt collects text.
Drafted with AI assistance and checked against the answer key.
Keep practicing
Take the free WEB-DEVELOPMENT-APPLICATIONS practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other WEB-DEVELOPMENT-APPLICATIONS practice questions
- Question 1Given the following JavaScript code: ```javascript var n1 = 10; var n2 = "20.39"; ``` Whi…
- Question 2Which attribute displays help text in an input field without specifying an actual value f…
- Question 4Which element attaches an external CSS document to a web page?
- Question 5Which HTML tag should a developer use to create a drop-down list?
- Question 8Which layout design is easiest to manage on a variety of devices?
- Question 9Which structure tag should a developer use to place contact information on a web page?
