Multiple choice technology web technology

How do you write "Hello World" in an alert box?

  1. alertBox="Hello World"

  2. msgBox("Hello World")

  3. alertBox("Hello World")

  4. alert("Hello World")

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In JavaScript, the standard window method used to display an alert dialog with a specified message is alert(). Distractors like alertBox and msgBox are incorrect because they are not built-in JavaScript functions, though MsgBox exists in VBScript.

AI explanation

To display the message "Hello World" in an alert box, you would use the alert() function. Let's go through each option to understand why it is correct or incorrect:

Option A) alertBox="Hello World" - This option is incorrect because alertBox is not a valid function or method in JavaScript. The correct function to display an alert box is alert().

Option B) msgBox("Hello World") - This option is incorrect because msgBox is not a valid function or method in JavaScript. The correct function to display an alert box is alert().

Option C) alertBox("Hello World") - This option is incorrect because alertBox is not a valid function or method in JavaScript. The correct function to display an alert box is alert().

Option D) alert("Hello World") - This option is correct because alert("Hello World") is the correct syntax to display the message "Hello World" in an alert box. The alert() function is a built-in JavaScript function that displays an alert box with the specified message.

The correct answer is Option D.