0
0
SASSmarkup~5 mins

@else and @else if branches in SASS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the @else directive do in Sass?
The @else directive runs a block of styles only if the previous @if or @else if condition was false. It acts like the "otherwise" case in decision making.
Click to reveal answer
beginner
How is @else if different from @else in Sass?
@else if lets you check another condition if the previous @if or @else if was false. @else runs only if all previous conditions were false, without checking a new condition.
Click to reveal answer
beginner
Write a simple Sass example using @if, @else if, and @else.
$color: blue; @if $color == red { background: red; } @else if $color == blue { background: blue; } @else { background: gray; } This sets background color based on the value of $color.
Click to reveal answer
intermediate
Can you have multiple @else if branches in Sass?
Yes, you can chain many @else if branches to check multiple conditions one after another before falling back to @else.
Click to reveal answer
beginner
What happens if none of the @if or @else if conditions are true and there is no @else?
No styles inside the conditional blocks will be applied. The Sass code inside those blocks is skipped.
Click to reveal answer
What does @else do in Sass?
ARuns if the previous <code>@if</code> or <code>@else if</code> condition is false
BRuns only if the previous condition is true
CChecks a new condition
DEnds the Sass file
Which directive lets you check another condition after an @if in Sass?
A<code>@else if</code>
B<code>@when</code>
C<code>@switch</code>
D<code>@else</code>
Can you use multiple @else if branches in Sass?
AOnly inside mixins
BNo, only one <code>@else if</code> is allowed
COnly if you use <code>@else</code> first
DYes, you can chain many <code>@else if</code> branches
What happens if no conditions match and there is no @else?
ASass throws an error
BThe last block runs anyway
CNo styles inside the conditional blocks run
DThe file stops compiling
Which of these is the correct syntax for @else if in Sass?
A@else if (condition) { }
B@else if condition { }
C@elseif (condition) { }
D@else if { condition }
Explain how @else if and @else work together in Sass conditional statements.
Think of it like a decision tree with multiple branches.
You got /4 concepts.
    Write a Sass snippet using @if, @else if, and @else to set a background color based on a variable.
    Use $color variable and compare it to color names.
    You got /5 concepts.