Challenge - 5 Problems
Boolean Logic Mastery in Sass
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the output color of this Sass code?
Given the following Sass code, what color will the
.box background be after compilation?SASS
$is-active: true; $has-error: false; .box { background-color: if($is-active and not $has-error, green, red); }
Attempts:
2 left
💡 Hint
Remember that
and requires both conditions to be true, and not reverses the boolean.✗ Incorrect
The variable $is-active is true and $has-error is false. The expression $is-active and not $has-error evaluates to true and true, which is true. So the if function returns green.
🧠 Conceptual
intermediate1:30remaining
Which Sass expression evaluates to
false?Select the Sass boolean expression that evaluates to
false.Attempts:
2 left
💡 Hint
Recall that
and requires both sides to be true to return true.✗ Incorrect
true and false is false. The others evaluate to true.
❓ rendering
advanced2:00remaining
What color will the
.alert box be?Consider this Sass code. What color will the
.alert background be after compiling to CSS?SASS
$error: false; $warning: true; .alert { background-color: if($error or $warning, orange, blue); }
Attempts:
2 left
💡 Hint
The
or operator returns true if either side is true.✗ Incorrect
$error is false, but $warning is true. So $error or $warning is true, making the background color orange.
❓ selector
advanced2:30remaining
Which selector applies styles only when both conditions are true?
Given these Sass variables, which selector will apply styles only if
$is-visible and $is-enabled are both true?SASS
$is-visible: true; $is-enabled: false; // Choose the correct selector
Attempts:
2 left
💡 Hint
Remember
and requires both to be true.✗ Incorrect
Option B applies styles only if both $is-visible and $is-enabled are true. The others apply styles under different conditions.
❓ accessibility
expert3:00remaining
How to use boolean logic in Sass to improve accessibility with focus styles?
You want to add a focus outline only if
$is-accessible is true and $user-prefers-focus is true. Which Sass code snippet correctly applies this logic?SASS
$is-accessible: true; $user-prefers-focus: false; .button { // Add focus outline conditionally }
Attempts:
2 left
💡 Hint
Focus outlines should appear only when both accessibility and user preference are true.
✗ Incorrect
Option A correctly uses and to require both $is-accessible and $user-prefers-focus to be true before applying the outline. The others apply the outline under incorrect conditions.