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 Creating Loops with @for and @each

advanced sass concepts- creating loops

/* Write your SCSS code below. */
@for $i from 1 through 3 
{
  .item_#{$i} 
  {
    width: $i * 100px;
  }
}

@each $color in red_box, blue_box, green_box {
  .color.#{$color} {
   background:darken(white,$i)
   }
  }
<!DOCTYPE html>
<html>
<head>
  <title>Sass Basics - Code Challenge</title>
  <link rel="stylesheet" type="text/css" href="page-style.css">
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <div class="item_1 red_box"></div>
  <div class="item_2 blue_box"></div>
  <div class="item_3 green_box"></div>
</body>
</html>
/* Write your SCSS code below. */
@for $i from 1 through 3 
{
  .item_#{$i} 
  {
    width: $i * 100px;
  }
}

@each $color in red_box, blue_box, green_box {
  .color.#{$color} {
   background:darken(white,$i)
   }
  }

where am i going wrong here please help

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

On Stage 2 of 2 of the Challenge, you need to create an @each loop for the list of $colors - 'red', 'blue', and 'green'. Within each iteration of the loop we create a class of .#{color}_box with a background-color of $color.

This information should provide the context to be able to complete the challenge..

If you have any other issues, feel free to ask. :)

Can someone post the correct code for both tasks 1 and 2?