Free Practice Quiz Question List

04 Conditionals and Boolean Logic Online Quiz Questions

Use this free practice quiz with 20 questions to review 04 Conditionals and Boolean Logic, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

A program uses if (score >= 60). What happens when score is exactly 60?

  1. A

    The condition requires a score greater than 60.

  2. B

    The condition rejects a score of exactly 60.

  3. C

    The condition accepts a score of exactly 60.

02
Choose one
1 point

A shipping rule is if (orderTotal >= 50 || isPremiumMember). Under which condition does the customer receive free shipping?

  1. A

    Free shipping requires both an order of at least $50 and premium membership.

  2. B

    Free shipping applies when the order is at least $50 or the customer is a premium member.

  3. C

    Free shipping applies only when the order is below $50 and the customer is not a premium member.

03
Choose one
1 point

What grade does this code assign when score is 95?

if (score >= 60) { grade = "D"; } else if (score >= 90) { grade = "A"; }

  1. A

    The first condition assigns D, because 95 already satisfies score >= 60.

  2. B

    The second condition assigns A, because the program always checks every branch.

  3. C

    The program assigns both D and A.

04
Choose all
1 point

A program allows entry only when age >= 18 && hasID is true. Select all cases that allow entry.

  1. A

    Age 20 with identification

  2. B

    Age 18 with identification

  3. C

    Age 20 without identification

  4. D

    Age 17 with identification

05
Choose all
1 point

Which rows make A || B true? Select all that apply.

  1. A

    A is false and B is false

  2. B

    A is false and B is true

  3. C

    A is true and B is false

  4. D

    A is true and B is true

06
True or false
1 point

True or false: If isClosed is false, the condition !isClosed evaluates to true.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: In a JavaScript switch, a default branch can handle a command that matches none of the listed case values.

  1. A

    True

  2. B

    False

08
Written response
1 point

What is the one-word name commonly used for JavaScript's compact conditional operator in an expression such as isOpen ? "Welcome" : "Closed"?

09
Written response
1 point

How many alternative code blocks does one if...else statement provide?

10
Fill in the blank
1 point

Complete the comparison.

Use switch when branches mainly depend on . Use if...else if when tests involve or complex Boolean expressions.

11
Open ended
1 point

A grading program should assign A for scores of 90 or higher, B for 80–89, C for 70–79, D for 60–69, and F below 60. Explain how you would structure the conditional branches and why their order matters. Include what should happen for scores 95, 60, and 59.

12
Choose one
1 point

Which interpretation matches if ((isMember || hasCoupon) && cartTotal >= 25)?

  1. A

    isMember && (hasCoupon || cartTotal >= 25)

  2. B

    (isMember || hasCoupon) && cartTotal >= 25

  3. C

    isMember || (hasCoupon && cartTotal >= 25)

13
True or false
1 point

True or false: In short-circuit evaluation, when the first operand of an AND expression is false, the second operand does not need to be evaluated.

  1. A

    True

  2. B

    False

14
Choose one
1 point

Why is an if...else if chain more natural than a switch for this logic?

if (temperature < 0) { print("Freezing"); } else if (temperature < 20) { print("Cool"); } else { print("Warm"); }

  1. A

    Because the conditions classify ranges of temperature rather than exact values.

  2. B

    Because switch cannot contain a default branch.

  3. C

    Because if...else if always executes every branch.

15
Fill in the blank
1 point

The operator that is true only when both Boolean expressions are true is .

16
Choose one
1 point

A program must classify a temperature as freezing when it is below 0, cool when it is below 20, and warm otherwise. Which structure is the most appropriate?

  1. A

    Use switch because it is always preferable for numeric decisions.

  2. B

    Use if...else if because the decisions are based on temperature ranges.

  3. C

    Use a nested conditional because switch cannot have more than two branches.

  4. D

    Use a ternary operator because it can represent any number of ranges.

17
Choose one
1 point

Which JavaScript condition uses strict equality to start the program only when the existing value of status is the string "ready"?

  1. A

    if (status === "ready") { start(); }

  2. B

    if (status = "ready") { start(); }

  3. C

    if (status == "ready") { start(); }

  4. D

    if (status !== "ready") { start(); }

18
Choose one
1 point

Which code uses JavaScript's conditional (ternary) operator to assign "Welcome" to message when isOpen is true and "Closed" otherwise?

  1. A

    const message = isOpen ? "Welcome" : "Closed";

  2. B

    const message = isOpen ? "Closed" : "Welcome";

  3. C

    const message = isOpen && "Welcome" || "Closed";

  4. D

    if (isOpen) { message = "Welcome"; } else { message = "Closed"; }

19
Written response
1 point

What is the programming technique called when a function handles an invalid or exceptional case early, then keeps the main path less indented?

20
Written response
1 point

Consider this nested conditional:

if (isLoggedIn) { if (isAdmin) { print("Show administration tools"); } else { print("Show standard tools"); } } else { print("Ask the user to log in"); }

If isLoggedIn is true and isAdmin is false, what message is printed?