Multiple choice javascript

Which has no syntax error ?

  1. alert("hello "+3+" times);

  2. alert("hello "+3 times);

  3. alert("hello +3+ times");

  4. alert("hello "+3 +" times);

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

Option C is the only syntactically valid alert. The string is properly quoted and closed. Options A, B, and D have mismatched or missing quotes.

AI explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) alert("hello "+3+" times); - This option is incorrect because it is missing a closing quotation mark after the word "times".

Option B) alert("hello "+3 times); - This option is incorrect because it is missing a closing quotation mark after the word "times" and it does not properly concatenate the string and the number.

Option C) alert("hello +3+ times"); - This option is correct because it includes the correct syntax for concatenating a string ("hello "), a number (3), and another string (" times").

Option D) alert("hello "+3 +" times); - This option is incorrect because it is missing a closing quotation mark after the word "times".

The correct answer is C. This option has no syntax errors because it correctly concatenates the string, number, and string using the + operator and includes the necessary quotation marks.