Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Sass Basics (retired) Advanced Sass Concepts Advanced Mixin Arguments

Neslee Rodillo
Neslee Rodillo
19,615 Points

help, do not understand the error message

challenge: Design a mixin (called "rainbow") that can take any number of colors via the argument $colors.... Within the mixin, use the loop @each $color in $colors to create a class named after each color, and set its background to the corresponding color.

My answer:

$color: black;

@mixin square ($size, $color){
    height: $size;
  width: $size;
  border: 1px solid $color;

}

.box { 
                @include square($color: red, $size: 10px); 

}

$colors: blue;

@mixin rainbow ($colors....) {
    @each $colors in $colors {
        .#($colors) {background-color:$colors;}
        }

}

Error: Bummer! You should use the value in $color as the name of a new class within the mixin

2 Answers

Ivan Uvarov
Ivan Uvarov
22,403 Points
  1. Use 3 dots after $colors instead of 4
  2. To create a loop use color in singular: @each $color in $colors. And use singular form of color inside a loop.
  3. Use curly braces to create class selector with a given color: .#{$color}
@mixin rainbow($colors...) {
    @each $color in $colors {
        .#{$color} {background-color:$color;}
    }
}