0
0
SASSmarkup~20 mins

Recursive mixins in SASS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Recursive Sass Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What does this recursive mixin output?
Consider this Sass recursive mixin that generates nested selectors. What CSS does it produce when called with @include nest(2);?
SASS
@mixin nest($level) {
  @if $level > 0 {
    .level-#{$level} {
      color: red;
      @include nest($level - 1);
    }
  }
}
A
.level-2 { color: red; }
.level-2 .level-1 { color: red; }
.level-1 { color: red; }
B
.level-2 { color: red; }
.level-2 .level-1 { color: red; }
C
.level-2 { color: red; }
.level-1 { color: red; }
D
.level-1 { color: red; }
.level-2 { color: red; }
Attempts:
2 left
💡 Hint
Think about how nested selectors combine in Sass when mixins call themselves inside a selector block.
📝 Syntax
intermediate
1:30remaining
Which option causes a syntax error in this recursive mixin?
Given this recursive mixin, which option will cause a syntax error when compiled?
SASS
@mixin countdown($n) {
  @if $n > 0 {
    .num-#{$n} {
      content: "#{$n}";
      @include countdown($n - 1);
    }
  }
}
A@include countdown();
B@include countdown(3);
C@include countdown(0);
D@include countdown(-1);
Attempts:
2 left
💡 Hint
Check if the mixin call provides the required argument.
rendering
advanced
2:30remaining
What is the rendered CSS output of this recursive mixin?
What CSS does this Sass code produce?
SASS
@mixin box-shadow-recursive($count) {
  @if $count > 0 {
    box-shadow: 0 0 #{$count}px rgba(0,0,0,0.1);
    @include box-shadow-recursive($count - 1);
  }
}

.box {
  @include box-shadow-recursive(2);
}
A
.box {
  box-shadow: 0 0 1px rgba(0,0,0,0.1);
  box-shadow: 0 0 2px rgba(0,0,0,0.1);
}
B
.box {
  box-shadow: 0 0 1px rgba(0,0,0,0.1);
}
C
.box {
  box-shadow: 0 0 2px rgba(0,0,0,0.1);
}
D
.box {
  box-shadow: 0 0 2px rgba(0,0,0,0.1);
  box-shadow: 0 0 1px rgba(0,0,0,0.1);
}
Attempts:
2 left
💡 Hint
Remember that later box-shadow properties override earlier ones unless combined.
selector
advanced
2:30remaining
Which option correctly generates nested selectors with recursive mixin?
This recursive mixin generates nested ul and li selectors. Which option shows the correct CSS output for @include nested-list(2);?
SASS
@mixin nested-list($depth) {
  @if $depth > 0 {
    ul {
      li {
        color: blue;
        @include nested-list($depth - 1);
      }
    }
  }
}
A
ul li {
  color: blue;
  ul li {
    color: blue;
  }
}
B
ul li {
  color: blue;
}
ul li li {
  color: blue;
}
C
ul li {
  color: blue;
}
ul li ul li {
  color: blue;
}
D
ul {
  li {
    color: blue;
  }
}
ul {
  li {
    color: blue;
  }
}
Attempts:
2 left
💡 Hint
Think about how nested selectors combine in Sass when mixins call themselves inside nested blocks.
accessibility
expert
3:00remaining
How can recursive mixins help improve accessibility in CSS?
Which of these is a valid way recursive mixins can be used to enhance accessibility in a web project?
ARecursively generating focus styles for nested interactive elements to ensure keyboard users see clear outlines.
BAutomatically hiding all nested elements recursively to reduce visual clutter without user control.
CRecursively increasing font size on all nested elements regardless of user preferences.
DUsing recursion to remove all ARIA attributes from nested elements to simplify markup.
Attempts:
2 left
💡 Hint
Think about how recursive styles can help users who navigate with keyboard.