Challenge - 5 Problems
Sass Conditional Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the output CSS of this Sass code?
Given the Sass mixin below, what CSS will be generated when
@include button-style(true); is used?SASS
@mixin button-style($primary) { @if $primary { background-color: blue; color: white; } @else { background-color: gray; color: black; } } .button { @include button-style(true); }
Attempts:
2 left
💡 Hint
Remember, the mixin uses @if to check if $primary is true or false.
✗ Incorrect
When $primary is true, the mixin sets background-color to blue and color to white. So the generated CSS for .button uses those colors.
🧠 Conceptual
intermediate2:00remaining
What error occurs if you forget the @if keyword in a conditional mixin?
Consider this Sass code snippet inside a mixin:
$primary {
background-color: blue;
}
What error will Sass produce?Attempts:
2 left
💡 Hint
Sass requires @if keyword to start a conditional block.
✗ Incorrect
Without @if, Sass does not recognize the condition and throws a syntax error expecting @if.
❓ selector
advanced2:00remaining
Which option produces the correct CSS for nested conditional mixins?
Given this Sass code, what CSS is generated?
@mixin theme($dark) {
@if $dark {
background: black;
color: white;
} @else {
background: white;
color: black;
}
}
.card {
@include theme(false);
border: 1px solid gray;
}Attempts:
2 left
💡 Hint
Check the value passed to the mixin and the @if condition.
✗ Incorrect
Since $dark is false, the @else block runs, setting background to white and color to black, plus the border property.
❓ layout
advanced2:00remaining
How does conditional mixin affect layout properties in this Sass code?
What is the rendered CSS for this Sass snippet?
@mixin layout($flex) {
@if $flex {
display: flex;
justify-content: center;
} @else {
display: block;
}
}
.container {
@include layout(true);
width: 100%;
}Attempts:
2 left
💡 Hint
The mixin sets display and justify-content only if $flex is true.
✗ Incorrect
Since $flex is true, display:flex and justify-content:center are included along with width:100%.
❓ accessibility
expert3:00remaining
Which Sass mixin usage best supports accessibility with conditional styling?
You want to create a button that changes style based on a high-contrast mode flag. Which option produces CSS that ensures good color contrast for accessibility?
SASS
@mixin accessible-button($highContrast) { @if $highContrast { background-color: black; color: yellow; border: 2px solid yellow; } @else { background-color: blue; color: white; border: none; } } .button { @include accessible-button(true); }
Attempts:
2 left
💡 Hint
High contrast mode uses black background with bright yellow text and border for visibility.
✗ Incorrect
Option C matches the mixin call with $highContrast true, providing strong contrast for accessibility.