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 Interpolating and if/else

Joga Gavidia
Joga Gavidia
4,047 Points

THE RIGHT CODE?

/* Write your SCSS code below. */
@mixin cars($make, $color){

    .#{$make} {
    border: 1px solid black;
    background-image: url("images/#{$color}.png");
  }  

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

a {
    color: red;
}

3 Answers

Whew, I struggled with this code challenge question for some reason (I'm going to blame it on the fact that I'm horribly sick at the moment ;) I tried out the code above just to get past the question, and it did work. Which is strange, because the code is completely wrong.

I went back to try my hand again and figured out where I went wrong. 1. I messed up creating the variable. Instead of writing $time: morning; I had written $time == morning; getting to involved in the operands. 2. still not completely sure about this, but originally I had written the strings using quotation marks like "morning" but ending up switching to an unquoted way. 3. I also made the sloppy mistake of using a # instead of $ for one of my variable names. So check your work!

In the end the code below worked. First, set the variable of $time. Then, and you want to keep this DRY and concise, define an anchor tag and write the if/else statement within.

I hope this helps others understand this code challenge if you too are running into issues!

$time: morning;

a {
    @if $time == morning {
    color: red;
  } @else if $time == afternoon {
    color: blue;
  } @else {
    color: gray;
  }
}
Joga Gavidia
Joga Gavidia
4,047 Points

It makes sense, thanks for the response.

Chris Shaw
Chris Shaw
26,676 Points

Hi Joga,

Do you get an error if you try to use the above code? It's a bit difficult to gauge if you're having a problem or not.

Joga Gavidia
Joga Gavidia
4,047 Points

No really, it works, but i feel like the code is wrong.