Challenge - 5 Problems
Sass Variable 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 code below, what will be the compiled CSS output?
SASS
$primary-color: #3498db; .button { background-color: $primary-color; color: white; }
Attempts:
2 left
💡 Hint
Remember that variables in Sass start with $ and are replaced with their values during compilation.
✗ Incorrect
The variable $primary-color is defined as #3498db. When compiled, Sass replaces $primary-color with #3498db in the CSS output.
🧠 Conceptual
intermediate2:00remaining
What error occurs if you use an undefined variable in Sass?
Consider this Sass code:
.button {
color: $text-color;
}
What happens when you compile this code?
SASS
.button { color: $text-color; }
Attempts:
2 left
💡 Hint
Sass requires variables to be declared before use.
✗ Incorrect
Using a variable that is not declared causes a compilation error because Sass cannot replace an undefined variable.
❓ selector
advanced2:00remaining
Which option correctly uses a variable inside a nested selector?
Given the variable declaration and nested selectors, which compiled CSS is correct?
SASS
$main-padding: 1rem; .container { padding: $main-padding; .content { padding: $main-padding; } }
Attempts:
2 left
💡 Hint
Nested selectors in Sass compile to combined selectors in CSS with variables replaced.
✗ Incorrect
Sass replaces variables with their values and compiles nested selectors into combined selectors in CSS.
❓ layout
advanced2:00remaining
How does changing a variable affect layout in Sass?
If you have this Sass code:
$gap-size: 2rem;
.grid {
display: grid;
gap: $gap-size;
}
What happens if you change $gap-size to 4rem and recompile?
SASS
$gap-size: 2rem; .grid { display: grid; gap: $gap-size; }
Attempts:
2 left
💡 Hint
Variables let you change values in one place to update styles everywhere.
✗ Incorrect
Changing $gap-size changes the gap property in the compiled CSS, affecting the space between grid items.
❓ accessibility
expert3:00remaining
How can Sass variables improve accessibility in color themes?
You want to create a dark mode theme using Sass variables for colors. Which approach best supports accessibility?
SASS
$text-color: #000; $background-color: #fff; body { color: $text-color; background-color: $background-color; }
Attempts:
2 left
💡 Hint
Accessibility needs clear contrast and easy theme switching.
✗ Incorrect
Using variables for colors allows easy switching between themes, improving accessibility by maintaining good contrast.