0
0
SASSmarkup~20 mins

Boolean values and logic in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Boolean Logic Mastery in Sass
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2: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);
}
Agreen
Byellow
Cblue
Dred
Attempts:
2 left
💡 Hint
Remember that and requires both conditions to be true, and not reverses the boolean.
🧠 Conceptual
intermediate
1:30remaining
Which Sass expression evaluates to false?
Select the Sass boolean expression that evaluates to false.
A$c: not false;
B$b: true or false;
C$a: true and false;
D$d: true and not false;
Attempts:
2 left
💡 Hint
Recall that and requires both sides to be true to return true.
rendering
advanced
2: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);
}
Ared
Bblue
Cgreen
Dorange
Attempts:
2 left
💡 Hint
The or operator returns true if either side is true.
selector
advanced
2: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
A.component { @if $is-visible or $is-enabled { color: black; } }
B.component { @if $is-visible and $is-enabled { color: black; } }
C.component { @if not $is-visible and $is-enabled { color: black; } }
D.component { @if $is-visible and not $is-enabled { color: black; } }
Attempts:
2 left
💡 Hint
Remember and requires both to be true.
accessibility
expert
3: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
}
A
.button {
  @if $is-accessible and $user-prefers-focus {
    outline: 2px solid blue;
  }
}
B
.button {
  @if not $is-accessible and $user-prefers-focus {
    outline: 2px solid blue;
  }
}
C
.button {
  @if $is-accessible or $user-prefers-focus {
    outline: 2px solid blue;
  }
}
D
.button {
  @if $is-accessible and not $user-prefers-focus {
    outline: 2px solid blue;
  }
}
Attempts:
2 left
💡 Hint
Focus outlines should appear only when both accessibility and user preference are true.