0
0
SASSmarkup~20 mins

@while loop usage in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SASS @while 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 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;
}
A
.item-1 { width: 10rem; }
.item-2 { width: 20rem; }
.item-3 { width: 30rem; }
B
.item-0 { width: 0rem; }
.item-1 { width: 10rem; }
.item-2 { width: 20rem; }
.item-3 { width: 30rem; }
C
.item-1 { width: 10rem; }
.item-2 { width: 20rem; }
DSyntaxError: Undefined variable $i
Attempts:
2 left
💡 Hint
Check if the variable $i is initialized before the @while loop.
rendering
intermediate
2: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;
}
ASyntaxError: Missing semicolon
B
.box-1 { height: 5rem; }
.box-2 { height: 10rem; }
C
.box-1 { height: 10rem; }
.box-2 { height: 20rem; }
D
.box-1 { height: 5rem; }
.box-2 { height: 5rem; }
Attempts:
2 left
💡 Hint
Remember the loop runs while $i is less or equal to 2, and height multiplies 5rem by $i.
selector
advanced
2: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.
A
$i: 1;
@while $i &lt;= 3 {
  .nav-#{$i} {
    color: blue;
  }
  $i: $i + 1;
}
B
@while $i &lt;= 3 {
  .nav-#{$i} {
    color: blue;
  }
  $i: $i + 1;
}
$i: 1;
C
}
;1 + i$ :i$  
}  
;eulb :roloc    
{ }i${#-van.  
{ 3 =&lt; i$ elihw@
;1 :i$
D
$i: 1;
@while $i &lt; 3 {
  .nav-#{$i} {
    color: blue;
  }
  $i: $i + 1;
}
Attempts:
2 left
💡 Hint
Initialization of $i must happen before the loop and the condition must include 3.
layout
advanced
2: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;
}
AThree columns with widths 15rem, 10rem, and 5rem, each with light gray background.
BThree columns all with width 5rem and light gray background.
CThree columns with widths 5rem, 10rem, and 15rem, each with light gray background.
DNo columns visible due to missing display property.
Attempts:
2 left
💡 Hint
Widths multiply 5rem by the column number, increasing size left to right.
accessibility
expert
3: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?
A
$i: 1;
@while $i &lt;= 4 {
  .btn-#{$i}:focus {
    outline: 0.1rem solid blue;
    outline-offset: 0.2rem * $i;
  }
  $i: $i + 1;
}
B
$i: 1;
@while $i &lt;= 4 {
  .btn-#{$i}:focus {
    outline: 0.1rem solid blue;
    outline-offset: 0.2rem;
  }
  $i: $i + 1;
}
C
$i: 1;
@while $i &lt;= 4 {
  .btn-#{$i}:focus {
    outline: 0.1rem * $i solid blue;
    outline-offset: 0.2rem * $i;
  }
  $i: $i + 1;
}
D
$i: 1;
@while $i &lt;= 4 {
  .btn-#{$i}:focus {
    outline: 0.1rem solid blue;
    outline-offset: 0.2rem * $i;
  }
}
Attempts:
2 left
💡 Hint
Multiply outline-offset by $i for increasing offset; outline thickness stays constant.