14. Which method should a developer use to create a message that requests a user to select "OK" or "Cancel"?"

Answer: D

Explanation:

Use the confirm method to create a message that requests a user to select "OK" or "Cancel".

The confirm method is specifically designed to display a dialog box with "OK" and "Cancel" options, allowing developers to prompt users for confirmation of an action.

A) prompt

The prompt method is used to display a dialog box that prompts the user for input, allowing them to enter a value. While it provides an input field, it does not specifically request a choice between "OK" or "Cancel", making it incorrect for this context.

B) alert

The alert method displays a message to the user but does not provide options for "OK" or "Cancel". It only has an "OK" button to dismiss the message, which does not meet the requirement of requesting a selection between two choices.

C) write

The write method is used to write content directly to the document in a web page. It does not create any dialog box or user prompts, and therefore is not applicable for creating a message that requests user input such as "OK" or "Cancel".

D) confirm

The confirm method creates a dialog box with "OK" and "Cancel" buttons, which directly aligns with the requirement to request a user's selection. This functionality is essential for scenarios where user confirmation is needed.

Conclusion

The confirm method is the only option that fulfills the requirement of prompting a user to select between "OK" or "Cancel". Other options either do not provide the necessary buttons or functionality to meet the question's criteria, confirming that D is the correct answer.