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

Gareth Edwards
Gareth Edwards
7,243 Points

Code challenge: creating loops with @for and @each.

The challenge states :

Use an @each loop to set the variable "$color" to the color red, then blue, and finally green. Use the loop to create three classes: ".red_box", ".blue_box", and ".green_box". The background color for each class should be set to the corresponding color.

@each $color in red, blue, green {
    .color.#{$color} {
    background-color: $color;
  }
}

I believe I'm doing somethin wrong by passing the background-color the value of the variable $color and I beleive I need to place ._box somewhere but I'm a little confused with this one.

The following error message is received: "Bummer! There should be a .red_box class with a red background. Did you set up the loop correctly?"

Any help would be greatly appreciated.

Many thanks. Gareth

2 Answers

Jorge Cruz
Jorge Cruz
19,305 Points

You didn't interpolate the class selector correctly.

@each $color in red, blue, green{
    .#{$color}_box{
    background-color:$color;
  }
}
Gareth Edwards
Gareth Edwards
7,243 Points

Ah yes, thanks for your help.