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?

Choose your answer, then check it against the explanation and the full breakdown below.

Which method allows the end user to enter text as an answer to a question as the page loads?
Answer options
Question 6 of 25

Question breakdown

Tests
Use browser dialog methods for user interaction
Difficulty
Easy

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

  1. The clue is that the user must 'enter text as an answer to a question'.
  2. alert only displays a message.
  3. confirm returns true or false from the OK and Cancel buttons.
  4. document.write outputs content and takes no input.
  5. prompt is the only option that collects typed text.

Each option

  • AIncorrect. document.write writes markup into the document and does not collect input.
  • BIncorrect. confirm returns a boolean from OK or Cancel, not text.
  • CCorrect. prompt displays a question with a text box and returns the entered string.
  • DIncorrect. alert shows a message with an OK button and returns no input.

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.

Start the free practice test

More questions

Other WEB-DEVELOPMENT-APPLICATIONS practice questions

Scroll to Top