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

I'm getting a false Bummer

With Task 4 of 4 I have read over and over the question. Not sure why I'm getting it wrong.

My code:

/* Write your SCSS code below. */
@mixin cars($make, $color){
.#{$make} {
border: 1px solid black;
background-image: url("#{$color}.png");
}
}

@mixin daytime($time){
@if $time == morning {
color: red;}
@else if $time == afternoon {
color: blue;}
@else {
color: gray;}
}
a { 
   @include daytime(morning);
}

edited to format the code.

6 Answers

Thank you for the help. I didn't know that we can set a variable by the example --> $time: morning; (found out without the "" around morning).

Here is what worked for me:

/* Write your SCSS code below. */
@mixin cars($make, $color){
.#{$make} {
border: 1px solid black;
background-image: url("#{$color}.png");
}
}
$time: morning;
@mixin daytime($time){
@if $time == morning {
color: red;}
@else if $time == afternoon {
color: blue;}
@else {
color: gray;}
}
a { 
   @include daytime($time);
}

Again thanks for the help!

Any time.

Hey all,

I would like to share another way in how to solve this challenge that worked with me.

here is my code:

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

$time: morning;
    @mixin daytime($time){
          a { 
            @if $time == morning {
             color: red;
             } @else if $time == afternoon {
             color: blue;
             } @else {
             color: gray;
             }
         }
     }
  @include daytime($time)

As you can see I define <a> inside the @mixin and at the end I just Included daytime with its variable.

Through out my learning process to become a programer I learned something which is in programing there is many ways to do the same thing and there is no limit on what we can do with code. Also there is no one best way to to write the code, it depends on the project that you working on. They way you right the code should match your hole project's code and its purpose.

Thank you & happy coding Wameedh

I don't remember this at all, but the directions for the challenge are:

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 should be blue. Finally, if the variable is set to anything else, the color should be gray.

I do not see where you have set the value "morning" in the variable $time.

I understood that it should color all anchor tags red when the variable is set to morning.

I have a mixin that I named daytime with a variable $time.

So I set $time variable as morning:

a { @include daytime(morning); }

Since $time is equal to morning the <a> tags will go red.

I tested this in workspaces and it worked but not in the challenge.

Remember that a computer is looking for certain things. I bet your code is more appropriate for a real deployment, but I have found it best to follow the directions exactly to pass the challenges. I failed with a setting variable error until I entered $time: "morning";

I then got a different error that I would have to watch the video to figure out.

jason chan
jason chan
31,009 Points
@mixin cars($make, $color){ .#{$make} { border: 1px solid black; background-image: url("#{$color}.png"); } } 


// if else statement
@mixin daytime($time){ 
@if $time == morning { color: red;} 
@else if $time == afternoon { color: blue;} 
@else { color: gray;} } 
// define your variable
$time: morning; 
// call your function 
a { 
@include daytime($time);
 }

Fixed for commenting.