Write a @each loop that creates classes .shadow-none, .shadow-light, and .shadow-heavy with the correct box-shadow property. Which code snippet is correct?
hard
A. @each $name, $shadow in $shadows { .shadow-#{$name} { box-shadow: $shadow; } }
B. @each $shadow, $name in $shadows { .shadow-#{$name} { box-shadow: $shadow; } }
C. @each $name in $shadows { .shadow-#{$name} { box-shadow: $name; } }
D. @each $name, $shadow in $shadows { .shadow-#{$shadow} { box-shadow: $name; } }
Solution
Step 1: Identify correct variable order for map iteration
Maps use @each $key, $value in $map, so $name is key and $shadow is value.
Step 2: Check class name and property usage
The class uses interpolation with the key $name, and the property uses the value $shadow.
Final Answer:
@each $name, $shadow in $shadows { .shadow-#{$name} { box-shadow: $shadow; } } -> Option A
Quick Check:
Key first, value second, use interpolation for class [OK]
Hint: Map loops: key first, value second, interpolate key for class [OK]
Common Mistakes:
Swapping key and value variables
Using only one variable for map
Interpolating value instead of key in class name
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.