Challenge - 5 Problems
Sass Logic Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why use logic in stylesheets?
Which of the following best explains why logic like variables and conditions is useful in stylesheets such as Sass?
Attempts:
2 left
💡 Hint
Think about how changing one value in many places can be simplified.
✗ Incorrect
Logic in stylesheets like variables and conditions helps keep code DRY (Don't Repeat Yourself). It lets you reuse values and apply styles only when needed, making maintenance easier.
📝 Syntax
intermediate2:00remaining
Sass variable usage
What will be the output CSS of this Sass code?
$main-color: #3498db;
.button {
background-color: $main-color;
}Attempts:
2 left
💡 Hint
Variables in Sass are replaced with their values in the output CSS.
✗ Incorrect
The Sass variable $main-color is replaced by its value #3498db in the compiled CSS.
❓ selector
advanced2:00remaining
Conditional styles with Sass
Given this Sass code, what background color will the
.alert class have?$type: 'error';
.alert {
@if $type == 'success' {
background-color: green;
} @else if $type == 'error' {
background-color: red;
} @else {
background-color: gray;
}
}Attempts:
2 left
💡 Hint
Check the value of $type and which condition matches.
✗ Incorrect
The variable $type is 'error', so the second condition applies, setting background color to red.
❓ layout
advanced2:00remaining
Using logic to create responsive layouts
How can Sass logic help create responsive layouts more efficiently?
Attempts:
2 left
💡 Hint
Think about reusing code blocks with different inputs.
✗ Incorrect
Sass mixins with parameters let you write media queries once and reuse them with different values, making responsive design easier and cleaner.
❓ accessibility
expert3:00remaining
Logic in stylesheets for accessibility
Which Sass feature can best help manage color contrast for accessibility across a website?
Attempts:
2 left
💡 Hint
Good contrast means text is easy to read on backgrounds.
✗ Incorrect
Functions that calculate color brightness can help decide if text should be light or dark to maintain good contrast, improving accessibility.