0
0
SASSmarkup~20 mins

@for loop (through vs to) in SASS - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Sass Loop Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Difference between @for ... through and @for ... to in Sass
What is the main difference between @for $i from 1 through 3 and @for $i from 1 to 3 in Sass?
ABoth <code>through</code> and <code>to</code> exclude the last number (3).
BThe <code>to</code> keyword includes the last number (3), while <code>through</code> excludes it.
CBoth <code>through</code> and <code>to</code> include the last number (3).
DThe <code>through</code> keyword includes the last number (3), while <code>to</code> excludes it.
Attempts:
2 left
💡 Hint
Think about whether the loop runs up to and including the last number or stops before it.
📝 Syntax
intermediate
1:30remaining
Output of @for loop with 'to' keyword
What CSS is generated by this Sass code?
@for $i from 1 to 4 {
  .item-#{$i} {
    width: 10px * $i;
  }
}
A
.item-1 { width: 10px; }
.item-2 { width: 20px; }
.item-3 { width: 30px; }
B
.item-1 { width: 10px; }
.item-2 { width: 20px; }
.item-3 { width: 30px; }
.item-4 { width: 40px; }
C
.item-1 { width: 10px; }
.item-2 { width: 20px; }
DSyntax error: missing semicolon after width value
Attempts:
2 left
💡 Hint
Remember that to excludes the last number.
rendering
advanced
2:00remaining
Visual result of @for loop with 'through' keyword
Given this Sass code:
@for $i from 1 through 3 {
  .box-#{$i} {
    height: 5rem * $i;
    background-color: lighten(#0077cc, 10% * $i);
  }
}

What will you see in the browser?
AThree boxes with heights 5rem, 10rem, 15rem and progressively lighter blue backgrounds.
BTwo boxes with heights 5rem and 10rem and the same blue background color.
CThree boxes with the same height 5rem but different background colors.
DNo boxes appear because of a syntax error.
Attempts:
2 left
💡 Hint
Check how many times the loop runs and how the properties change with $i.
selector
advanced
2:00remaining
Selector generated by nested @for loops with 'to' and 'through'
What selectors are generated by this Sass code?
@for $i from 1 to 3 {
  @for $j from 1 through 2 {
    .item-#{$i}-#{$j} {
      content: "#{$i}-#{$j}";
    }
  }
}
A.item-1-1, .item-1-2, .item-2-1, .item-2-2, .item-3-1, .item-3-2
BSyntax error due to nested loops
C.item-1-1, .item-1-2, .item-2-1, .item-2-2
D.item-1-1, .item-2-1, .item-3-1
Attempts:
2 left
💡 Hint
Remember the difference in loop ranges for to and through.
accessibility
expert
2:30remaining
Accessibility impact of using @for loops for generating classes
When using Sass @for loops to generate multiple classes for UI elements, what accessibility consideration should you keep in mind?
ALoops in Sass prevent keyboard navigation by default.
BEnsure that generated classes do not rely solely on color for conveying information, to support users with color blindness.
CUsing loops automatically adds ARIA labels to all generated elements.
DGenerated classes should always use <code>display:none</code> to hide content from screen readers.
Attempts:
2 left
💡 Hint
Think about how visual styles affect users with different abilities.