0
0
SASSmarkup~20 mins

@each loop over lists in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass @each Loop 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 @each loop?
Given the following Sass code, what CSS will it generate?
SASS
@each $color in red, green, blue {
  .text-#{$color} {
    color: $color;
  }
}
A
.text-red {
  color: red;
}
.text-green {
  color: blue;
}
.text-blue {
  color: green;
}
B
.text-red, .text-green, .text-blue {
  color: red, green, blue;
}
C
.text-red {
  color: red;
}
.text-green {
  color: green;
}
.text-blue {
  color: blue;
}
D
.text-#{$color} {
  color: $color;
}
Attempts:
2 left
💡 Hint
Remember that @each loops over each item and creates separate blocks.
🧠 Conceptual
intermediate
1:30remaining
How many CSS classes are generated by this @each loop?
Consider this Sass code: @each $size in small, medium, large, x-large { .btn-#{$size} { font-size: $size; } } How many CSS classes will be generated?
A0
B3
C1
D4
Attempts:
2 left
💡 Hint
Count the number of items in the list after @each.
selector
advanced
2:00remaining
Which option produces the correct CSS selectors from this @each loop?
Given this Sass code: @each $icon in home, user, settings { .icon-#{$icon}::before { content: "\f#{$icon}"; } } Which CSS selectors are generated?
A.icon-home::before, .icon-user::before, .icon-settings::before
B.icon-home, .icon-user, .icon-settings
C.icon-#{$icon}::before
D.icon-home::after, .icon-user::after, .icon-settings::after
Attempts:
2 left
💡 Hint
Look carefully at the pseudo-element used and the interpolation.
layout
advanced
2:30remaining
What visual layout results from this Sass @each loop with Flexbox?
This Sass code generates CSS for colored boxes: $colors: red, green, blue; .container { display: flex; } @each $color in $colors { .box-#{$color} { background-color: $color; width: 5rem; height: 5rem; margin: 0.5rem; } } What will you see in the browser?
AOne large square with a gradient from red to blue.
BThree colored squares (red, green, blue) arranged side by side horizontally with space between them.
CThree colored squares stacked vertically with no space.
DNo visible boxes because width and height are missing.
Attempts:
2 left
💡 Hint
Flexbox arranges children in a row by default.
accessibility
expert
3:00remaining
Which option correctly uses @each loop to generate accessible button styles with ARIA roles?
You want to create buttons with different themes and ensure each button has an ARIA role for accessibility. Which Sass code correctly generates buttons with roles and styles?
A
@each $theme in primary, secondary, danger {
  .btn-#{$theme}[role="button"] {
    background-color: map-get($colors, $theme);
    cursor: pointer;
  }
}
B
@each $theme in primary, secondary, danger {
  .btn-#{$theme} {
    background-color: map-get($colors, $theme);
    &[role="button"] {
      cursor: pointer;
    }
  }
}
C
@each $theme in primary, secondary, danger {
  .btn-#{$theme} {
    background-color: map-get($colors, $theme);
    role: button;
  }
}
D
@each $theme in primary, secondary, danger {
  .btn-#{$theme} {
    background-color: map-get($colors, $theme);
    aria-role: button;
  }
}
Attempts:
2 left
💡 Hint
ARIA roles are HTML attributes, not CSS properties. Use attribute selectors in CSS.