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?✗ Incorrect
If the condition is false and no
@else is provided, Sass skips the styles inside the @if block.Which of these is a valid Sass
@if condition?✗ Incorrect
Sass supports numeric comparisons like
5 > 3. Option C is invalid because 'color' is undefined (though == is valid for equality), B uses = which is assignment, and D compares undefined 'font-size'.What keyword do you use to add a fallback style if
@if condition is false?✗ Incorrect
@else runs styles when the @if condition is false.Can you nest
@if statements inside each other in Sass?✗ Incorrect
Sass allows nesting
@if statements inside each other for complex conditions.What will this Sass code output?<br>
$size: 10px; @if $size > 5px { font-size: $size; }✗ Incorrect
The variable $size is 10px, which is greater than 5px, so the condition is true and outputs
font-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.