0
0
SASSmarkup~20 mins

@else and @else if branches in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass Conditional Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What color will the button have?
Given the following Sass code, what will be the background color of the button when $status is set to 'warning'?
SASS
$status: warning;

button {
  @if $status == success {
    background-color: green;
  } @else if $status == error {
    background-color: red;
  } @else {
    background-color: yellow;
  }
}
Abackground-color: green;
Bbackground-color: red;
Cbackground-color: yellow;
DNo background color applied
Attempts:
2 left
💡 Hint
Think about which condition matches the value 'warning'.
🧠 Conceptual
intermediate
1:30remaining
Which statement about @else if and @else is true?
Choose the correct statement about how @else if and @else branches work in Sass conditionals.
A@else if runs regardless of previous conditions.
B@else if runs only if all previous @if and @else if conditions are false.
C@else can have a condition like @else if.
D@else if and @else can be used without an initial @if.
Attempts:
2 left
💡 Hint
Think about the flow of conditional checks.
rendering
advanced
2:00remaining
What color will the paragraph text be?
Given this Sass code, what color will the paragraph text have when $theme is 'dark'?
SASS
$theme: dark;

p {
  @if $theme == light {
    color: black;
  } @else if $theme == dark {
    color: white;
  } @else {
    color: gray;
  }
}
Acolor: white;
BNo color applied
Ccolor: gray;
Dcolor: black;
Attempts:
2 left
💡 Hint
Check which condition matches 'dark'.
selector
advanced
2:00remaining
Which selector will be styled when $device is 'tablet'?
Consider this Sass code. Which CSS selector will get the styles when $device is 'tablet'?
SASS
$device: tablet;

.container {
  @if $device == mobile {
    display: block;
  } @else if $device == tablet {
    display: flex;
  } @else {
    display: grid;
  }
}
A.container { display: flex; }
B.container { display: block; }
C.container { display: grid; }
DNo styles applied
Attempts:
2 left
💡 Hint
Match the $device value with the conditions.
accessibility
expert
2:30remaining
How to use @else if for accessible color contrast?
You want to set text color based on background color variable $bg. Which Sass code ensures accessible contrast by choosing black text on light backgrounds and white text on dark backgrounds using @else if?
A
$bg: light;

.text {
  @if $bg == dark {
    color: white;
  } @else if $bg == light {
    color: black;
  } @else {
    color: gray;
  }
}
B
$bg: light;

.text {
  @if $bg == dark {
    color: black;
  } @else if $bg == light {
    color: white;
  } @else {
    color: gray;
  }
}
C
$bg: light;

.text {
  @if $bg == light {
    color: white;
  } @else if $bg == dark {
    color: black;
  } @else {
    color: gray;
  }
}
D
$bg: light;

.text {
  @if $bg == light {
    color: black;
  } @else if $bg == dark {
    color: white;
  } @else {
    color: gray;
  }
}
Attempts:
2 left
💡 Hint
Light backgrounds need dark text for contrast.