Recall & Review
beginner
What does the
@each loop do in Sass?It repeats a block of styles for each item in a list or map, helping you write less code and keep styles consistent.
Click to reveal answer
beginner
How do you write an
@each loop to go through a list of colors named $colors?You write: <br>
@each $color in $colors {<br> /* styles using $color */<br>}Click to reveal answer
intermediate
Can
@each loop handle multiple variables at once?Yes! If the list contains sublists, you can unpack them like: <br>
@each $name, $value in $list {<br> /* use $name and $value */<br>}Click to reveal answer
beginner
Why use
@each loop instead of writing styles manually?It saves time, reduces mistakes, and makes your code easier to update because you change the list once and all styles update automatically.
Click to reveal answer
intermediate
What happens if you use
@each with an empty list?The loop does nothing and no styles are generated, so it’s safe to use even if the list might be empty.
Click to reveal answer
What keyword starts a loop over a list in Sass?
✗ Incorrect
The
@each keyword is used to loop over lists or maps in Sass.How do you access each item in the list inside an
@each loop?✗ Incorrect
You declare a variable after
in to represent each item as the loop runs.Which of these is a valid
@each loop syntax for a list $sizes?✗ Incorrect
The correct syntax is
@each $variable in $list { ... }.If a list contains pairs like
(name, value), how do you loop over them?✗ Incorrect
You can unpack pairs by listing multiple variables separated by commas.
What happens if the list used in
@each is empty?✗ Incorrect
The loop simply does nothing and no styles are output.
Explain how to use the
@each loop in Sass to style multiple elements with different colors.Think about how you would paint different walls with different colors using a list.
You got /3 concepts.
Describe the benefits of using
@each loops over writing repetitive CSS manually.Imagine changing many similar things at once by changing just one list.
You got /4 concepts.