0
0
SASSmarkup~20 mins

Variable interpolation with #{} in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Interpolation 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 using interpolation?
Given the Sass code below, what will be the compiled CSS output?
SASS
$color: red;

.button-#{$color} {
  background-color: $color;
}
A
.button-#color {
  background-color: red;
}
B
.button-#{$color} {
  background-color: red;
}
C
.button-red {
  background-color: $color;
}
D
.button-red {
  background-color: red;
}
Attempts:
2 left
💡 Hint
Interpolation replaces #{} with the variable's value inside selectors or property names.
rendering
intermediate
2:00remaining
What color will the button have in the browser?
Consider this Sass code. What color will the button have when rendered in the browser?
SASS
$btn-color: blue;

.btn-#{$btn-color} {
  color: $btn-color;
}
AGreen text color on the button
BNo color applied, default text color
CBlue text color on the button
DRed text color on the button
Attempts:
2 left
💡 Hint
The variable $btn-color is set to blue and used both in selector and property.
🧠 Conceptual
advanced
2:00remaining
Why use #{} interpolation in Sass selectors?
Which reason best explains why #{} interpolation is used in Sass selectors?
ATo import external CSS files
BTo insert variable values dynamically into selectors or property names
CTo create loops inside selectors
DTo comment out code inside selectors
Attempts:
2 left
💡 Hint
Think about how variables can change parts of selectors.
selector
advanced
2:00remaining
What selector does this Sass code produce?
Given the Sass code below, what is the exact CSS selector generated after compilation?
SASS
$state: active;

.menu-item-#{$state} {
  font-weight: bold;
}
A.menu-item-active
B.menu-item-#{$state}
C.menu-item-state
D.menu-item-$state
Attempts:
2 left
💡 Hint
Interpolation replaces #{$state} with the variable's value.
accessibility
expert
3:00remaining
How can interpolation help with accessible ARIA attributes in Sass?
You want to create multiple buttons with different ARIA labels using Sass variables and interpolation. Which Sass code correctly sets unique ARIA labels using interpolation?
A
$label: submit;
button[aria-label="#{$label}"] {
  background: green;
}
B
$label: submit;
button[aria-label=$label] {
  background: green;
}
C
$label: submit;
button[aria-label='label'] {
  background: green;
}
D
$label: submit;
button[aria-label=#{label}] {
  background: green;
}
Attempts:
2 left
💡 Hint
Attribute selectors need the variable value as a string inside quotes with interpolation.