Bird
Raised Fist0
SASSmarkup~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the Sass function map-get($map, $key) do?
easy
A. It adds a new key-value pair to the map.
B. It deletes a key from the map.
C. It returns the value associated with the given key in the map.
D. It converts the map into a list.

Solution

  1. Step 1: Understand the purpose of map-get

    The function map-get is designed to retrieve a value from a Sass map using a key.
  2. Step 2: Identify the correct behavior

    It does not modify the map but simply returns the value for the specified key.
  3. Final Answer:

    It returns the value associated with the given key in the map. -> Option C
  4. Quick Check:

    map-get returns value by key [OK]
Hint: Remember: map-get fetches values, it doesn't change the map. [OK]
Common Mistakes:
  • Thinking map-get adds or removes keys
  • Confusing map-get with map-merge
  • Expecting map-get to return the whole map
2. Which of the following is the correct syntax to get the value of key "primary-color" from a Sass map $colors?
easy
A. map-get($colors, "primary-color");
B. map-get($colors, primary_color);
C. map-get($colors, 'primary_color');
D. map-get($colors, primary-color);

Solution

  1. Step 1: Check key format in Sass maps

    Keys that are strings must be quoted with double or single quotes in Sass.
  2. Step 2: Identify correct syntax for string key

    Using double quotes around "primary-color" is correct; single quotes also work but only one option uses quotes properly.
  3. Final Answer:

    map-get($colors, "primary-color"); -> Option A
  4. Quick Check:

    String keys need quotes in map-get [OK]
Hint: Always quote string keys in map-get to avoid errors. [OK]
Common Mistakes:
  • Not quoting string keys
  • Using underscores instead of hyphens
  • Confusing variable names with keys
3. Given the Sass map:
$settings: ("font-size": 16px, "color": #333, "margin": 1rem);

What will map-get($settings, "color") return?
medium
A. #333
B. 16px
C. 1rem
D. null

Solution

  1. Step 1: Locate the key "color" in the map

    The map has a key "color" with value #333.
  2. Step 2: Use map-get to retrieve the value

    Calling map-get with "color" returns #333 exactly.
  3. Final Answer:

    #333 -> Option A
  4. Quick Check:

    map-get returns #333 for "color" key [OK]
Hint: Match the key exactly to get the correct value. [OK]
Common Mistakes:
  • Mixing up keys and values
  • Expecting map-get to return the whole map
  • Using wrong key names
4. What is the problem with this Sass code?
$theme: (primary: #0055ff, secondary: #ffaa00);
$color: map-get($theme, "primary");
medium
A. The key "primary" should not be quoted because keys are unquoted.
B. The map keys are unquoted but the key in map-get is quoted, causing null.
C. There is no problem; the code works correctly.
D. map-get requires the map variable to be quoted.

Solution

  1. Step 1: Check key types in the map

    The map keys are unquoted identifiers: primary and secondary.
  2. Step 2: Check key usage in map-get

    Using a quoted string "primary" does not match the unquoted key primary, so map-get returns null.
  3. Final Answer:

    The map keys are unquoted but the key in map-get is quoted, causing null. -> Option B
  4. Quick Check:

    Key types must match in map and map-get [OK]
Hint: Match quotes exactly between map keys and map-get keys. [OK]
Common Mistakes:
  • Mixing quoted and unquoted keys
  • Expecting map-get to find keys regardless of quotes
  • Assuming map-get throws error on mismatch
5. You have a nested Sass map:
$themes: (
  light: ("background": #fff, "text": #000),
  dark: ("background": #000, "text": #fff)
);

How do you get the text color for the dark theme using map-get?
hard
A. map-get($themes, dark, text);
B. map-get($themes, "dark", "text");
C. map-get($themes[dark][text]);
D. map-get(map-get($themes, dark), "text");

Solution

  1. Step 1: Understand nested map structure

    $themes is a map where each key (light, dark) maps to another map.
  2. Step 2: Access nested map values step-by-step

    First, get the dark map with map-get($themes, dark), then get "text" from that map with map-get(..., "text").
  3. Final Answer:

    map-get(map-get($themes, dark), "text"); -> Option D
  4. Quick Check:

    Use nested map-get calls for nested maps [OK]
Hint: Use map-get inside map-get for nested maps. [OK]
Common Mistakes:
  • Trying to pass multiple keys in one map-get
  • Using incorrect syntax for nested access
  • Assuming bracket notation works in Sass maps
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard