Challenge - 5 Problems
Sass Map Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Understanding map-get behavior
What will be the output of the following Sass code snippet?
Assuming this code is compiled to CSS, what will
$colors: (primary: #ff0000, secondary: #00ff00); $result: map-get($colors, tertiary);
Assuming this code is compiled to CSS, what will
$result contain?SASS
$colors: (primary: #ff0000, secondary: #00ff00); $result: map-get($colors, tertiary);
Attempts:
2 left
💡 Hint
Think about what happens when you ask for a key that does not exist in a Sass map.
✗ Incorrect
The
map-get function returns null if the key is not found in the map. It does not throw an error or return a default color.📝 Syntax
intermediate2:00remaining
Correct syntax for map-merge
Which option correctly merges two Sass maps
$map1 and $map2 so that keys in $map2 overwrite those in $map1?SASS
$map1: (a: 1, b: 2); $map2: (b: 3, c: 4); $result: ???
Attempts:
2 left
💡 Hint
Remember the order of arguments in
map-merge affects which keys overwrite.✗ Incorrect
The first argument is the original map, and the second argument's keys overwrite or add to it. So
map-merge($map1, $map2) merges $map2 into $map1, overwriting keys like 'b'.❓ selector
advanced2:00remaining
Using map-keys in a loop
Given the Sass map below, what will be the output CSS after compiling?
$fonts: (heading: 'Arial', body: 'Helvetica', caption: 'Courier');
@each $key in map-keys($fonts) {
.font-#{$key} {
font-family: map-get($fonts, $key);
}
}SASS
$fonts: (heading: 'Arial', body: 'Helvetica', caption: 'Courier'); @each $key in map-keys($fonts) { .font-#{$key} { font-family: map-get($fonts, $key); } }
Attempts:
2 left
💡 Hint
Check how string quotes in Sass map values are handled when compiled to CSS.
✗ Incorrect
Sass preserves quotes around string values in maps when outputting CSS. So font-family values will be quoted strings.
❓ layout
advanced2:00remaining
Dynamic grid layout with map-get
Consider this Sass code that uses a map to define grid column sizes:
What will be the value of
$grid-sizes: (small: 1fr, medium: 2fr, large: 3fr);
.container {
display: grid;
grid-template-columns: map-get($grid-sizes, medium) map-get($grid-sizes, small) map-get($grid-sizes, large);
}What will be the value of
grid-template-columns in the compiled CSS?SASS
$grid-sizes: (small: 1fr, medium: 2fr, large: 3fr); .container { display: grid; grid-template-columns: map-get($grid-sizes, medium) map-get($grid-sizes, small) map-get($grid-sizes, large); }
Attempts:
2 left
💡 Hint
Remember the order of arguments in the property and how map-get returns values.
✗ Incorrect
The property sets columns in the order: medium, small, large. map-get returns the values for those keys, so the output is '2fr 1fr 3fr'.
❓ accessibility
expert3:00remaining
Using Sass maps for accessible color themes
You have a Sass map defining color themes for accessibility:
What is the background and text color of the
$themes: (
light: (background: #ffffff, text: #000000),
dark: (background: #000000, text: #ffffff)
);
.theme-light {
background-color: map-get(map-get($themes, light), background);
color: map-get(map-get($themes, light), text);
}
.theme-dark {
background-color: map-get(map-get($themes, dark), background);
color: map-get(map-get($themes, dark), text);
}What is the background and text color of the
.theme-dark class in the compiled CSS?SASS
$themes: ( light: (background: #ffffff, text: #000000), dark: (background: #000000, text: #ffffff) ); .theme-light { background-color: map-get(map-get($themes, light), background); color: map-get(map-get($themes, light), text); } .theme-dark { background-color: map-get(map-get($themes, dark), background); color: map-get(map-get($themes, dark), text); }
Attempts:
2 left
💡 Hint
Check the nested map values for the 'dark' theme keys.
✗ Incorrect
The nested map for 'dark' has background #000000 and text #ffffff, so those values appear in the compiled CSS.