0
0
SASSmarkup~20 mins

Accessing map values with map-get in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Map-Get Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2:00remaining
What is the output of this Sass code using map-get?
Given the Sass map and the code below, what color will be assigned to background-color?
SASS
$colors: (primary: #ff0000, secondary: #00ff00, accent: #0000ff);

.my-class {
  background-color: map-get($colors, secondary);
}
Abackground-color: #00ff00;
Bbackground-color: #ff0000;
Cbackground-color: #0000ff;
Dbackground-color: null;
Attempts:
2 left
💡 Hint
Remember that map-get retrieves the value for the given key in the map.
🧠 Conceptual
intermediate
2:00remaining
What happens if the key does not exist in the map?
Consider this Sass code snippet. What will be the value of color in the CSS output?
SASS
$theme-colors: (light: #eee, dark: #333);

.text {
  color: map-get($theme-colors, medium);
}
Acolor: null;
Bcolor: #eee;
Ccolor: #333;
DSyntax error during compilation
Attempts:
2 left
💡 Hint
If the key is missing, map-get returns null.
selector
advanced
2:30remaining
Which option correctly accesses a nested map value with map-get?
Given the nested map below, which option correctly gets the value #123456?
SASS
$palette: (
  theme1: (primary: #abcdef, secondary: #fedcba),
  theme2: (primary: #123456, secondary: #654321)
);
Amap-get($palette, theme2, primary)
Bmap-get($palette, theme2.primary)
Cmap-get($palette, primary)
Dmap-get(map-get($palette, theme2), primary)
Attempts:
2 left
💡 Hint
Use map-get twice to access nested maps.
layout
advanced
2:30remaining
What CSS output results from this Sass map-get usage in a grid layout?
Given the Sass code below, what is the final CSS for the grid container's grid-template-columns?
SASS
$grid-settings: (columns: 3, gap: 1rem);

.container {
  display: grid;
  grid-template-columns: repeat(map-get($grid-settings, columns), 1fr);
  gap: map-get($grid-settings, gap);
}
A
display: grid;
grid-template-columns: repeat(3, 3fr);
gap: 1rem;
B
display: grid;
grid-template-columns: repeat(1fr, 3);
gap: 1rem;
C
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
D
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: null;
Attempts:
2 left
💡 Hint
map-get returns the value for the key, which is used inside repeat() and gap.
accessibility
expert
3:00remaining
How can map-get help improve accessibility in theming?
Consider a Sass map storing color themes for accessibility. Which approach correctly uses map-get to apply a high-contrast color for better readability?
SASS
$accessibility-colors: (normal: #333, high-contrast: #000000);

.text {
  color: map-get($accessibility-colors, high-contrast);
}
AIt sets color to null, so the text color is inherited and may not be accessible.
BIt applies a very dark color #000000 for high contrast, improving readability for users with vision impairments.
CIt causes a compilation error because 'high-contrast' is not a valid key.
DIt applies #333 which is too light and reduces contrast, making text harder to read.
Attempts:
2 left
💡 Hint
High contrast colors help users with vision difficulties read text better.