Challenge - 5 Problems
Sass Scope Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding variable scope in Sass
What will be the value of
$color after compiling this Sass code?SASS
$color: blue; @mixin change-color() { $color: red; } @include change-color(); body { color: $color; }
Attempts:
2 left
💡 Hint
Think about whether the variable inside the mixin changes the global variable or just a local copy.
✗ Incorrect
In Sass, variables inside mixins are local by default. The
$color inside change-color does not affect the global $color. So, the body color remains blue.📝 Syntax
intermediate2:00remaining
Using !global to change variable scope
What will be the color of the
p element after compiling this Sass code?SASS
$font-size: 12px; @mixin set-font() { $font-size: 16px !global; } @include set-font(); p { font-size: $font-size; }
Attempts:
2 left
💡 Hint
The
!global flag changes the variable in the global scope.✗ Incorrect
Using
!global inside the mixin updates the global $font-size variable to 16px. So, the p element uses 16px font size.❓ rendering
advanced2:00remaining
Effect of variable scope on nested selectors
Given this Sass code, what color will the
.container .title text be in the compiled CSS?SASS
$text-color: black; .container { $text-color: green; .title { color: $text-color; } } .title { color: $text-color; }
Attempts:
2 left
💡 Hint
Variables inside a selector are local to that selector and its children.
✗ Incorrect
Inside
.container, $text-color is green locally, so .container .title uses green. Outside, $text-color is black, so .title uses black.❓ selector
advanced2:00remaining
Variable scope impact on @function output
What will be the output of
colorize() function when called in this Sass code?SASS
$base-color: blue; @function colorize() { $base-color: red; @return $base-color; } .result { color: colorize(); }
Attempts:
2 left
💡 Hint
Variables inside functions are local unless marked global.
✗ Incorrect
Inside the function,
$base-color is locally set to red. The function returns this local value, so the color is red.❓ accessibility
expert3:00remaining
Ensuring accessible color variables with global scope
You want to define a global color variable for accessible text contrast in Sass. Which approach correctly sets a global variable that can be used anywhere, including inside mixins and functions?
Attempts:
2 left
💡 Hint
Global variables must be declared with
!global if set inside a block.✗ Incorrect
Option B sets
$accessible-color globally with !global. Options B and C set local variables inside mixin/function. Option B sets global only if at root level, but if inside a block it won't be global.