A program uses if (score >= 60). What happens when score is exactly 60?
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.
A shipping rule is if (orderTotal >= 50 || isPremiumMember). Under which condition does the customer receive free shipping?
- A
Free shipping requires both an order of at least $50 and premium membership.
- B
Free shipping applies when the order is at least $50 or the customer is a premium member.
- C
Free shipping applies only when the order is below $50 and the customer is not a premium member.
What grade does this code assign when score is 95?
if (score >= 60) {
grade = "D";
} else if (score >= 90) {
grade = "A";
}
- A
The first condition assigns
D, because 95 already satisfiesscore >= 60. - B
The second condition assigns
A, because the program always checks every branch. - C
The program assigns both
DandA.
A program allows entry only when age >= 18 && hasID is true. Select all cases that allow entry.
- A
Age 20 with identification
- B
Age 18 with identification
- C
Age 20 without identification
- D
Age 17 with identification
Which rows make A || B true? Select all that apply.
- A
A is false and B is false
- B
A is false and B is true
- C
A is true and B is false
- D
A is true and B is true
True or false: If isClosed is false, the condition !isClosed evaluates to true.
- A
True
- B
False
True or false: In a JavaScript switch, a default branch can handle a command that matches none of the listed case values.
- A
True
- B
False
What is the one-word name commonly used for JavaScript's compact conditional operator in an expression such as isOpen ? "Welcome" : "Closed"?
How many alternative code blocks does one if...else statement provide?
Complete the comparison.
Use switch when branches mainly depend on . Use if...else if when tests involve or complex Boolean expressions.
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.
Which interpretation matches if ((isMember || hasCoupon) && cartTotal >= 25)?
- A
isMember && (hasCoupon || cartTotal >= 25) - B
(isMember || hasCoupon) && cartTotal >= 25 - C
isMember || (hasCoupon && cartTotal >= 25)
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.
- A
True
- B
False
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");
}
- A
Because the conditions classify ranges of temperature rather than exact values.
- B
Because
switchcannot contain adefaultbranch. - C
Because
if...else ifalways executes every branch.
The operator that is true only when both Boolean expressions are true is .
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?
- A
Use switch because it is always preferable for numeric decisions.
- B
Use if...else if because the decisions are based on temperature ranges.
- C
Use a nested conditional because switch cannot have more than two branches.
- D
Use a ternary operator because it can represent any number of ranges.
Which JavaScript condition uses strict equality to start the program only when the existing value of status is the string "ready"?
- A
if (status === "ready") { start(); } - B
if (status = "ready") { start(); } - C
if (status == "ready") { start(); } - D
if (status !== "ready") { start(); }
Which code uses JavaScript's conditional (ternary) operator to assign "Welcome" to message when isOpen is true and "Closed" otherwise?
- A
const message = isOpen ? "Welcome" : "Closed";
- B
const message = isOpen ? "Closed" : "Welcome";
- C
const message = isOpen && "Welcome" || "Closed";
- D
if (isOpen) { message = "Welcome"; } else { message = "Closed"; }
What is the programming technique called when a function handles an invalid or exceptional case early, then keeps the main path less indented?
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?