0
0
SASSmarkup~20 mins

Variable declaration with $ in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2: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;
}
ASyntaxError: Undefined variable $primary-color
B
.button {
  background-color: #3498db;
  color: white;
}
C
.button {
  background-color: blue;
  color: white;
}
D
.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.
🧠 Conceptual
intermediate
2: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;
}
AThe compiler will ignore the color property.
BThe color will default to black automatically.
CThe CSS output will have color: $text-color; unchanged.
DCompilation error: Undefined variable $text-color.
Attempts:
2 left
💡 Hint
Sass requires variables to be declared before use.
selector
advanced
2: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;
  }
}
A
.container {
  padding: 1rem;
}
.container .content {
  padding: 1rem;
}
B
.container {
  padding: $main-padding;
}
.content {
  padding: $main-padding;
}
C
.container {
  padding: 1rem;
  .content {
    padding: 1rem;
  }
}
DSyntaxError: Nested selectors cannot use variables
Attempts:
2 left
💡 Hint
Nested selectors in Sass compile to combined selectors in CSS with variables replaced.
layout
advanced
2: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;
}
ACompilation error because $gap-size cannot be changed.
BThe gap remains 2rem because variables don't affect layout.
CThe space between grid items doubles from 2rem to 4rem.
DThe grid layout breaks and items overlap.
Attempts:
2 left
💡 Hint
Variables let you change values in one place to update styles everywhere.
accessibility
expert
3: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;
}
ADefine separate variables for light and dark modes and switch them using a class on the body.
BUse only one variable for all colors to keep it simple.
CHardcode colors directly in CSS without variables for better performance.
DAvoid using variables because they confuse screen readers.
Attempts:
2 left
💡 Hint
Accessibility needs clear contrast and easy theme switching.