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

Please help with this code challenge.

I really need help with part two of this question. http://teamtreehouse.com/library/interpolating-and-ifelse

I did attempt it, here is my code.

@mixin cars ($make, $color) {
  .#($make).make {
    color: $color;
    @if $make == bkack (){
      border: black 1px solid;
    }
  }
}

4 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Leon;

You have a syntax error in your code. Sass interpolation has a syntax of # {}. Not # () as you have. In addition it seems you have some additional code.

The code for Task 2 needs to look similar to:

@mixin cars($make, $color) {
    .#{$make} {
      border: 1px solid black;
    }
}

If you look at the video around the 1:45 mark you will see the syntax needed.

Happy coding,

Ken

Thank you so much.

I am so sorry, I must be annoying you, but I find Sass very difficult. I need help with number three.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Leon;

No problem at all. That is what the forum is all about!

Task 3 asks us to: Add a background-image to the class. Append .png to the value stored in $color to form the file name.

Within our previously defined class we need to add something to the background-image property, right? And we are adding a file so we need to use the url("") value. Our code then goes to:

@mixin cars($make, $color) {
    .#{$make} {
      border: 1px solid black;
      background-image: url("???");
    }
}

I'm sure you got that far. The interpolation seems to be where folks get stuck. Similar to Task 2, where we use the #{} notation for making our class name, we can interpolate the value of $color into the url value for the background-image property. We would do that by:

background-image: url("#{$color}");

We are also asked to append .png to the end of the $color value. This, therefore, sounds like we would have a bunch of .png files saved of various color names that we are using as our background image. Anyway, to append the .png we just type it in right after our interpolated string and prior to the closing quote. So our line of code for Task 3, which needs to be included with everything else, would be:

background-image: url("#{$color}.png");

Hope it helps and makes some sense.

Ken

Oh my god, thanks so much. I appreciate that you have explained it to me as well.

Last time I will be bothering you for the night. I need help with the fourth. I did attempt this one but am having a bit of a struggle. I am not sure where I would put the color: blue; and I think my Syntax is wrong.

@mixin cars($make, $color) {
    .#{$make} {
      border: 1px solid black;
     background-image: url("#{$color}.png");
     $morning: $time;
     @if $time == $morning {
        a {
          color: blue;
        }
     }
    }
}
Ken Alger
STAFF
Ken Alger
Treehouse Teacher

You are on the right track, my friend.

Here's the instructions for Task 4:

Underneath the previous code, store the value "morning" in a variable named $time. Then write an if/else directive that will color all a tags. If the variable $time is equal to "morning", the color should be red. Otherwise, if the variable is "afternoon", the color be blue. Finally, if the variable is set to anything else, the color should be gray.

First off, you need to move all of your Task 4 related code outside of the previous class & @mixin declarations. That will meet the requirements for the first part of the first sentence.

Second, to set the variable $time to the value of morning we would use

$time: morning;

Right now you are setting a variable $morning to a value of the variable $time with $morning: $time;.

Onto the meat of this challenge. We will be targeting the a tags so we need to select them and put our if/else directive inside that code block. I'll lay out the basics of this statement and let you have a go at completing it, okay? (Don't want to take all of the fun away from your SCSS experience :smile:).

$time: morning;

a {
  @if $time == morning {
   // what happens if it is morning
  } @else if ??? {  // next condition goes here
   // what happens if it is the next condition
  } @else {
   // when all else fails, do this line of code
  }
}

Post back if you're still stuck.

Ken

I am stuck, I got this. It keeps saying I am missing a bracket.

@mixin cars($make, $color) {
    .#{$make} {
      border: 1px solid black;
     background-image: url("#{$color}.png");
     $time: morning;
     a {
  @if $time == morning {
   color: red;
  } @else if  $afternoon { 
   color: blue;
  } @else {
   color: gray;
  }
}
        }
     }
    }
}
Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Leon;

A couple of things first you need to move all of the code for Task 4 outside of the @mixin cars rule. Secondly in your @else if statement you have not created a proper if statement for this challenge. It needs to look like the conditional for $time == morning but with the different condition, $time == afternoon.

You should wind up then with two separate code blocks in your SASS:

@mixin cars ($make, $color) {

// mixin code here

}

a {

// Task 4 code here

}

Ken

I am so confused. I keep getting errors, I am not sure what I am doing wrong.

css'''

@mixin cars($make, $color) { .#{$make} { border: 1px solid black; background-image: url("#{$color}.png"); } } $time: morning; $time: afternoon;

a { @if $time == morning { color: red; } @else if $time == afternoon { color: blue; } @else { color: gray; } } } } } }

'''

Ken Alger
Ken Alger
Treehouse Teacher

Leon;

I'm on my mobile now so I can't write code snippets, but you don't want to define $time twice, just once for morning. And check your bracket pairs in your a code block.

I'll be able to write code again later.

Ken

I got it! Thanks so much, all thanks to you my friend. I also had way to much brackets. Thank you so much man.