Bird
Raised Fist0
SASSmarkup~20 mins

Variable arguments in mixins in SASS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Variable Arguments Mastery
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 mixin usage?
Given the following SASS code, what CSS will be generated?
@mixin box-shadow($shadows...) {
  -webkit-box-shadow: $shadows;
  box-shadow: $shadows;
}

.box {
  @include box-shadow(2px 2px 5px #333, inset 0 0 10px #666);
}
SASS
@mixin box-shadow($shadows...) {
  -webkit-box-shadow: $shadows;
  box-shadow: $shadows;
}

.box {
  @include box-shadow(2px 2px 5px #333, inset 0 0 10px #666);
}
A
.box {
  -webkit-box-shadow: 2px 2px 5px #333, inset 0 0 10px #666;
  box-shadow: 2px 2px 5px #333, inset 0 0 10px #666;
}
B
.box {
  -webkit-box-shadow: (2px 2px 5px #333, inset 0 0 10px #666);
  box-shadow: (2px 2px 5px #333, inset 0 0 10px #666);
}
C
.box {
  -webkit-box-shadow: 2px 2px 5px #333 inset 0 0 10px #666;
  box-shadow: 2px 2px 5px #333 inset 0 0 10px #666;
}
D
.box {
  -webkit-box-shadow: 2px 2px 5px #333;
  box-shadow: inset 0 0 10px #666;
}
Attempts:
2 left
💡 Hint
Remember that variable arguments in SASS are treated as a list and when used directly, they are joined by commas.
🧠 Conceptual
intermediate
1:30remaining
What type is the variable argument inside a SASS mixin?
In SASS, when you define a mixin with variable arguments like $args..., what type does $args have inside the mixin?
AA list containing all passed arguments
BA string concatenation of all arguments
CA map with keys as argument positions
DA single value of the first argument only
Attempts:
2 left
💡 Hint
Think about how SASS collects multiple arguments passed to a mixin.
❓ selector
advanced
2:00remaining
Which option correctly applies variable arguments in a nested selector?
Consider this SASS mixin that applies multiple colors as shadows. Which option correctly uses variable arguments to apply all shadows inside a nested selector?
@mixin multi-shadow($shadows...) {
  .shadowed {
    box-shadow: $shadows;
  }
}
SASS
@mixin multi-shadow($shadows...) {
  .shadowed {
    box-shadow: $shadows;
  }
}
A@include multi-shadow(1px, 1px, 2px, black, 0, 0, 5px, red);
B@include multi-shadow((1px 1px 2px black, 0 0 5px red));
C@include multi-shadow(1px 1px 2px black 0 0 5px red);
D@include multi-shadow(1px 1px 2px black, 0 0 5px red);
Attempts:
2 left
💡 Hint
Variable arguments accept multiple comma-separated values.
❓ layout
advanced
2:00remaining
What CSS layout is produced by this SASS mixin with variable arguments?
Given this SASS mixin that sets multiple margin values using variable arguments, what is the resulting CSS?
@mixin set-margins($values...) {
  margin: $values;
}

.box {
  @include set-margins(1rem, 2rem, 3rem, 4rem);
}
SASS
@mixin set-margins($values...) {
  margin: $values;
}

.box {
  @include set-margins(1rem, 2rem, 3rem, 4rem);
}
A
.box {
  margin: 1rem, 2rem, 3rem, 4rem;
}
B
.box {
  margin: 1rem 2rem 3rem 4rem;
}
C
.box {
  margin: (1rem 2rem 3rem 4rem);
}
D
.box {
  margin: 1rem;
  margin: 2rem;
  margin: 3rem;
  margin: 4rem;
}
Attempts:
2 left
💡 Hint
CSS margin property expects space-separated values, not commas.
❓ accessibility
expert
2:30remaining
How can variable arguments in SASS mixins help improve accessibility in responsive design?
You want to create a SASS mixin that accepts any number of padding values for different screen sizes to improve spacing for accessibility. Which approach best uses variable arguments to achieve this?
AUse variable arguments but apply only the first value for all screen sizes to keep it simple.
BUse fixed padding values inside the mixin and ignore variable arguments for consistency.
CUse a variable argument to accept multiple padding values and apply them inside media queries for different breakpoints.
DAvoid variable arguments and write separate mixins for each screen size.
Attempts:
2 left
💡 Hint
Think about how variable arguments can handle flexible input for multiple cases.

Practice

(1/5)
1. What does using ...$args in a Sass mixin allow you to do?
easy
A. Automatically convert arguments to strings
B. Limit the mixin to only one argument
C. Accept any number of arguments as a list inside the mixin
D. Prevent the mixin from accepting arguments

Solution

  1. Step 1: Understand the ...$args syntax

    This syntax in Sass mixins means the mixin can take any number of arguments, which are collected into a list named $args.
  2. Step 2: Recognize the flexibility it provides

    Because the arguments are stored as a list, you can use them inside the mixin to apply styles dynamically based on how many arguments are passed.
  3. Final Answer:

    Accept any number of arguments as a list inside the mixin -> Option C
  4. Quick Check:

    Variable arguments = flexible input list [OK]
Hint: Look for ...$args to accept many inputs [OK]
Common Mistakes:
  • Thinking it limits to one argument
  • Assuming arguments become strings automatically
  • Believing it disables arguments
2. Which of the following is the correct way to define a Sass mixin that accepts variable arguments?
easy
A. @mixin example($args...) { /* code */ }
B. @mixin example(...$args) { /* code */ }
C. @mixin example(args...) { /* code */ }
D. @mixin example($args..) { /* code */ }

Solution

  1. Step 1: Recall Sass syntax for variable arguments

    In Sass, the correct syntax to accept variable arguments in a mixin is to place three dots after the argument name: $args....
  2. Step 2: Identify the correct option

    @mixin example($args...) { /* code */ } correctly uses $args... inside the mixin definition, which is the valid Sass syntax.
  3. Final Answer:

    @mixin example($args...) { /* code */ } -> Option A
  4. Quick Check:

    Variable args syntax = $args... [OK]
Hint: Remember: dots come after variable name, no parentheses [OK]
Common Mistakes:
  • Putting dots before the variable name
  • Using parentheses incorrectly
  • Confusing with JavaScript rest syntax
3. Given the Sass mixin:
@mixin colors($colors...) {
  @each $color in $colors {
    .text-#{$color} {
      color: $color;
    }
  }
}

What CSS will be generated by:
@include colors(red, blue, green);
medium
A. .text-red { color: red; } .text-blue { color: blue; } .text-green { color: green; }
B. .text-red, .text-blue, .text-green { color: red, blue, green; }
C. .text-red { color: red; } .text-blue { color: blue; }
D. Syntax error due to incorrect argument usage

Solution

  1. Step 1: Understand the mixin behavior

    The mixin takes variable arguments as a list $colors. It loops over each color and creates a CSS class with the color name and sets the text color.
  2. Step 2: Apply the mixin with three colors

    When called with red, blue, green, it generates three classes: .text-red, .text-blue, and .text-green, each with the corresponding color style.
  3. Final Answer:

    .text-red { color: red; } .text-blue { color: blue; } .text-green { color: green; } -> Option A
  4. Quick Check:

    Loop over args creates separate classes [OK]
Hint: Variable args loop creates one style per argument [OK]
Common Mistakes:
  • Combining all colors in one selector
  • Missing the loop causing only one class
  • Syntax errors from wrong argument usage
4. What allows this Sass mixin that uses variable arguments to output valid CSS padding values?
@mixin padding($values...) {
  padding: $values;
}

When used as @include padding(10px, 20px);, it outputs valid CSS padding values.
medium
A. The mixin must use @each to apply padding multiple times
B. Variable arguments can be used with padding property
C. The mixin should use parentheses around $values
D. You must join the list into a space-separated string before using

Solution

  1. Step 1: Identify how variable arguments are stored

    Variable arguments are collected into a space-separated list. padding: $values; serializes the list with spaces, producing valid CSS for shorthand properties like padding.
  2. Step 2: No additional processing needed

    The mixin must use @each to apply padding multiple times adds unnecessary loop; C adds unneeded parens; D manual join is redundant since the list is already space-separated.
  3. Final Answer:

    Variable arguments can be used with padding property -> Option B
  4. Quick Check:

    Var args list = space-separated for shorthands [OK]
Hint: Variable args work directly with shorthand CSS properties [OK]
Common Mistakes:
  • Thinking @each is required for multiple values
  • Believing parentheses are needed around $values
  • Assuming manual string joining is necessary
5. You want a Sass mixin that accepts any number of margin values and applies them correctly. Which mixin code correctly handles 1 to 4 arguments using variable arguments and outputs valid CSS?
hard
A. @mixin margin($values...) { margin: #{join($values, ' ')}; }
B. @mixin margin($values...) { margin: unquote($values); }
C. @mixin margin($values...) { @each $val in $values { margin: $val; } }
D. @mixin margin($values...) { margin: $values; }

Solution

  1. Step 1: Understand the need for space-separated values

    Variable arguments form a space-separated list, ideal for CSS shorthand properties like margin.
  2. Step 2: Evaluate each option

    A uses incorrect join argument order (requires join(' ', $values)); B correctly uses margin: $values; for space-separated output; C loops creating multiple margin rules (invalid); D misuses unquote on list.
  3. Final Answer:

    @mixin margin($values...) { margin: $values; } -> Option D
  4. Quick Check:

    Direct $values for shorthand properties [OK]
Hint: Directly assign $args... to shorthand properties [OK]
Common Mistakes:
  • Reversing arguments in list.join()
  • Looping and repeating CSS property
  • Using unquote() on argument lists
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard