0
0
SASSmarkup~20 mins

sass:map module - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass Map Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding map-get behavior
What will be the output of the following Sass code snippet?
$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);
A#ff0000
Bnull
C#000000
DError: Key 'tertiary' not found
Attempts:
2 left
💡 Hint
Think about what happens when you ask for a key that does not exist in a Sass map.
📝 Syntax
intermediate
2: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: ???
Amap-merge($map1, map-merge($map2, $map1))
Bmap-merge($map2, $map1)
Cmap-merge($map1, $map2)
Dmap-merge($map1, $map2, $map1)
Attempts:
2 left
💡 Hint
Remember the order of arguments in map-merge affects which keys overwrite.
selector
advanced
2: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);
  }
}
A
.font-heading { font-family: Arial; }
.font-body { font-family: Helvetica; }
.font-caption { font-family: Courier; }
BError: map-keys cannot be used in @each loops
C
.font-heading { font-family: map-get($fonts, heading); }
.font-body { font-family: map-get($fonts, body); }
.font-caption { font-family: map-get($fonts, caption); }
D
.font-heading { font-family: 'Arial'; }
.font-body { font-family: 'Helvetica'; }
.font-caption { font-family: 'Courier'; }
Attempts:
2 left
💡 Hint
Check how string quotes in Sass map values are handled when compiled to CSS.
layout
advanced
2:00remaining
Dynamic grid layout with map-get
Consider this Sass code that uses a map to define grid column sizes:
$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);
}
Agrid-template-columns: 2fr 1fr 3fr;
Bgrid-template-columns: 1fr 2fr 3fr;
Cgrid-template-columns: map-get($grid-sizes, medium) map-get($grid-sizes, small) map-get($grid-sizes, large);
Dgrid-template-columns: 3fr 2fr 1fr;
Attempts:
2 left
💡 Hint
Remember the order of arguments in the property and how map-get returns values.
accessibility
expert
3:00remaining
Using Sass maps for accessible color themes
You have a Sass map defining color themes for accessibility:
$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);
}
Abackground-color: #000000; color: #ffffff;
Bbackground-color: #ffffff; color: #000000;
Cbackground-color: map-get(map-get($themes, dark), background); color: map-get(map-get($themes, dark), text);
Dbackground-color: #111111; color: #eeeeee;
Attempts:
2 left
💡 Hint
Check the nested map values for the 'dark' theme keys.