0
0
SASSmarkup~5 mins

@if conditional logic in SASS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the @if directive do in Sass?
The @if directive lets you write conditional code in Sass. It runs certain styles only if a condition is true.
Click to reveal answer
beginner
How do you write an @if statement in Sass?
You write @if (condition) { /* styles here */ }. The styles inside run only if the condition is true.
Click to reveal answer
beginner
Can you use @else with @if in Sass? What does it do?
Yes. @else runs styles if the @if condition is false. It helps handle two cases clearly.
Click to reveal answer
beginner
Example: What will this Sass code output?<br>
@if 5 > 3 { color: blue; }
Since 5 is greater than 3, the condition is true. The output CSS will be:<br>
color: blue;
Click to reveal answer
intermediate
Why use @if in Sass instead of plain CSS?
CSS alone can't do conditions. Sass @if lets you write smarter styles that change based on variables or logic, saving time and code.
Click to reveal answer
What happens if the @if condition is false and there is no @else?
AThe styles inside <code>@if</code> are skipped.
BThe styles inside <code>@if</code> run anyway.
CSass throws an error.
DThe styles inside <code>@if</code> run twice.
Which of these is a valid Sass @if condition?
A@if (5 > 3) { ... }
B@if color = blue { ... }
C@if (color == blue) { ... }
D@if (font-size > 12px) { ... }
What keyword do you use to add a fallback style if @if condition is false?
A@elseif
B@else
C@otherwise
D@fallback
Can you nest @if statements inside each other in Sass?
ANo, nesting is not allowed.
BOnly one level of nesting is allowed.
CYes, nesting <code>@if</code> is allowed.
DOnly with <code>@else</code>.
What will this Sass code output?<br>
$size: 10px; @if $size > 5px { font-size: $size; }
AError because of wrong syntax.
BNo output because variables can't be compared.
Cfont-size: 5px;
Dfont-size: 10px;
Explain how the @if directive works in Sass and give a simple example.
Think about how you decide to do something only if a condition is met.
You got /3 concepts.
    Describe the difference between @if and @else in Sass conditional logic.
    Consider how you choose between two options based on a yes/no question.
    You got /3 concepts.