What is the expected result when you run this script in the browser?


Consider the following code:

What is the expected result when you run this script in the browser?

A.
A window alert box will display Hello.

B.
A window alert box will display Goodbye.

C.
No window alert box will appear because there is an error in the code.

D.
A window alert box will display Hello then a second alert box will display Goodbye.

Explanation:



Discussion

6 Responses to “What is the expected result when you run this script in the browser?”

  1. Joshua says:

    This is definitely B, not A. Please fix.

  2. Jane says:

    It is A. The condition shows an assignment operation. As long as that assignment isn’t 0, the answer is “Truthy”, and the first statement clause will execute.

  3. Joshua says:

    You are correct, Jane. It’s A. Thanks for pointing that out.

  4. Joshua says:

    I somehow overlooked the “=” and just read it as “if(HighNum==6)…”. My mistake.

  5. Chicco says:

    A is the correct answer. Assignment returns true so “Hello” is displayed.

Post a Comment