Bird
Raised Fist0
SASSmarkup~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. In Sass, which of the following represents a Boolean value?
easy
A. 1
B. "true"
C. "false"
D. true

Solution

  1. Step 1: Understand Sass Boolean values

    In Sass, Boolean values are the keywords true and false, not strings or numbers.
  2. Step 2: Identify the correct Boolean

    true uses true as a keyword, which is the correct Boolean value in Sass.
  3. Final Answer:

    true -> Option D
  4. Quick Check:

    Boolean values in Sass are true or false [OK]
Hint: Look for keywords true or false without quotes [OK]
Common Mistakes:
  • Confusing strings "true" or "false" with Boolean values
  • Using numbers like 1 or 0 as Booleans
  • Thinking true/false must be quoted
2. Which of the following is the correct syntax to use a Boolean in an @if statement in Sass?
easy
A. @if $is-active == true { color: blue; }
B. @if $is-active = true { color: blue; }
C. @if $is-active === true { color: blue; }
D. @if $is-active != true { color: blue; }

Solution

  1. Step 1: Check Sass comparison operator

    Sass uses == to compare values in @if statements, not = or ===.
  2. Step 2: Identify correct syntax

    @if $is-active == true { color: blue; } uses == correctly to compare $is-active with true.
  3. Final Answer:

    @if $is-active == true { color: blue; } -> Option A
  4. Quick Check:

    Use double equals (==) for comparison in Sass [OK]
Hint: Use double equals (==) for comparisons in @if [OK]
Common Mistakes:
  • Using single equals (=) which assigns instead of compares
  • Using triple equals (===) which is invalid in Sass
  • Using != when checking for true
3. What color will the following Sass code output?
$dark-mode: false;

body {
  @if $dark-mode {
    background-color: black;
  } @else {
    background-color: white;
  }
}
medium
A. white
B. black
C. transparent
D. red

Solution

  1. Step 1: Check the Boolean value of $dark-mode

    $dark-mode is set to false, so the @if condition is false.
  2. Step 2: Follow the @else branch

    Since the condition is false, the code inside @else runs, setting background-color to white.
  3. Final Answer:

    white -> Option A
  4. Quick Check:

    False condition triggers @else block [OK]
Hint: False triggers @else styles, not @if [OK]
Common Mistakes:
  • Assuming false runs the @if block
  • Confusing true/false values
  • Ignoring the @else block
4. Identify the error in this Sass code:
$is-visible: true

.container {
  @if $is-visible == true {
    display: block;
  } @else {
    display: none;
  }
}
medium
A. Incorrect use of @else block
B. Wrong comparison operator in @if
C. Missing semicolon after variable declaration
D. Variable name cannot start with $

Solution

  1. Step 1: Check variable declaration syntax

    In Sass, variable declarations must end with a semicolon. Here, $is-visible: true is missing a semicolon.
  2. Step 2: Verify other syntax

    The comparison operator == and @else block are correct. Variable names can start with $.
  3. Final Answer:

    Missing semicolon after variable declaration -> Option C
  4. Quick Check:

    Variable declarations need semicolons [OK]
Hint: Check for missing semicolons after variables [OK]
Common Mistakes:
  • Forgetting semicolon after variable assignment
  • Confusing = and == in @if
  • Thinking @else is optional syntax
5. You want to apply a red border only if both $is-error and $is-active are true in Sass. Which code correctly uses Boolean logic to do this?
hard
A. @if $is-error & $is-active { border: 1px solid red; }
B. @if $is-error and $is-active { border: 1px solid red; }
C. @if $is-error && $is-active { border: 1px solid red; }
D. @if $is-error or $is-active { border: 1px solid red; }

Solution

  1. Step 1: Understand Sass Boolean operators

    Sass uses the keyword and for logical AND, not symbols like && or &.
  2. Step 2: Identify correct syntax

    @if $is-error and $is-active { border: 1px solid red; } correctly uses and to check if both variables are true before applying the border.
  3. Final Answer:

    @if $is-error and $is-active { border: 1px solid red; } -> Option B
  4. Quick Check:

    Use and for logical AND in Sass [OK]
Hint: Use 'and' keyword for AND logic in Sass [OK]
Common Mistakes:
  • Using && or & which are invalid in Sass
  • Using 'or' instead of 'and' for both true
  • Confusing bitwise & with logical and
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard