Challenge - 5 Problems
SASS @while Loop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
What is the output CSS of this SASS code using @while loop?
Consider the following SASS code. What CSS does it produce?
SASS
$i: 1; @while $i <= 3 { .item-#{$i} { width: 10rem * $i; } $i: $i + 1; }
Attempts:
2 left
💡 Hint
Check if the variable $i is initialized before the @while loop.
✗ Incorrect
In SASS, variables must be initialized before use. Here, $i is used without initialization, causing an error.
❓ rendering
intermediate2:00remaining
What CSS is generated by this correct @while loop in SASS?
Given this SASS code, what CSS does it output?
SASS
$i: 1; @while $i <= 2 { .box-#{$i} { height: 5rem * $i; } $i: $i + 1; }
Attempts:
2 left
💡 Hint
Remember the loop runs while $i is less or equal to 2, and height multiplies 5rem by $i.
✗ Incorrect
The loop runs for $i = 1 and 2, generating .box-1 with height 5rem and .box-2 with height 10rem.
❓ selector
advanced2:30remaining
Which option correctly generates selectors .nav-1, .nav-2, .nav-3 using @while loop?
Choose the SASS code that produces CSS selectors .nav-1, .nav-2, and .nav-3.
Attempts:
2 left
💡 Hint
Initialization of $i must happen before the loop and the condition must include 3.
✗ Incorrect
Option A initializes $i before the loop and loops while $i <= 3, producing .nav-1, .nav-2, .nav-3 selectors.
❓ layout
advanced2:30remaining
What visual layout results from this SASS @while loop generating grid columns?
This SASS code creates grid columns with widths increasing by 5rem. What is the final layout?
SASS
$i: 1; .container { display: grid; grid-template-columns: repeat(3, auto); } @while $i <= 3 { .col-#{$i} { width: 5rem * $i; background: lightgray; } $i: $i + 1; }
Attempts:
2 left
💡 Hint
Widths multiply 5rem by the column number, increasing size left to right.
✗ Incorrect
The loop creates .col-1, .col-2, .col-3 with widths 5rem, 10rem, 15rem respectively, visible as grid columns.
❓ accessibility
expert3:00remaining
How to use @while loop in SASS to generate accessible focus styles for buttons?
You want to create focus outlines with increasing thickness for buttons .btn-1 to .btn-4 using @while loop. Which SASS code correctly does this and supports accessibility?
Attempts:
2 left
💡 Hint
Multiply outline-offset by $i for increasing offset; outline thickness stays constant.
✗ Incorrect
Option A correctly multiplies outline-offset by $i for increasing spacing, uses valid outline syntax, and increments $i properly.