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 trialGareth Edwards
7,243 PointsCode 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
19,305 PointsYou didn't interpolate the class selector correctly.
@each $color in red, blue, green{
.#{$color}_box{
background-color:$color;
}
}
Gareth Edwards
7,243 PointsAh yes, thanks for your help.
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Pointsalborz
Full Stack JavaScript Techdegree Graduate 30,885 PointsCurious -- why is there a "_box" appended to the .#($color) variable below the @each line of code? Thanks