Which JavaScript method should display a welcome message when the site loads?

Prepare for the CIW Advanced HTML5 and CSS3 Specialist Exam. Study effectively with comprehensive materials, flashcards, and engaging multiple-choice questions. Enhance your expertise and get ready to succeed!

Multiple Choice

Which JavaScript method should display a welcome message when the site loads?

Explanation:
Showing a welcome message when the page loads is best done with a simple modal dialog that the user must acknowledge. The alert method does exactly this: it displays a message in a pop-up dialog with an OK button and blocks further interaction until the user dismisses it. That immediacy and visibility make it ideal for a welcome note that you want noticed right away as the site loads. Logging to the console wouldn’t reach the user unless they open developer tools, so it wouldn’t serve as a visible welcome message. A confirm dialog provides OK and Cancel options, which is for a decision, not just a notification. A prompt asks for text input, which isn’t appropriate for a simple greeting. If you want the message to appear automatically on load, call the alert in a script that runs after the page has loaded, such as in a script tag at the end of the body or inside a DOMContentLoaded handler.

Showing a welcome message when the page loads is best done with a simple modal dialog that the user must acknowledge. The alert method does exactly this: it displays a message in a pop-up dialog with an OK button and blocks further interaction until the user dismisses it. That immediacy and visibility make it ideal for a welcome note that you want noticed right away as the site loads.

Logging to the console wouldn’t reach the user unless they open developer tools, so it wouldn’t serve as a visible welcome message. A confirm dialog provides OK and Cancel options, which is for a decision, not just a notification. A prompt asks for text input, which isn’t appropriate for a simple greeting.

If you want the message to appear automatically on load, call the alert in a script that runs after the page has loaded, such as in a script tag at the end of the body or inside a DOMContentLoaded handler.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy