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 trialDaniele Manca
10,986 PointsWhat's wrong with my code?
This challenge is not passing, I get an error saying that the @else should come after @if, but it is, isn't it?
/* Write your SCSS code below. */
@mixin cars ($make, $color) {
.make.#{$make} {
border: 1px solid black;
background-image: url("#{$color}.png");
}
$time: morning;
@if $time == morning {
a {
color: red;
}
@else if $time == afternoon {
a {
color: blue
}
}
@else {
a {
color: gray;
}
}
}
}
Robert Richey
Courses Plus Student 16,352 PointsHi Ben,
I fixed the markdown for the posted code. If you're curious about how to add markdown like this on your own, checkout this thread on posting code to the forum . Also, there is a link at the bottom called Markdown Cheatsheet that gives a brief overview of how to add markdown to your posts.
Cheers!
3 Answers
Robert Richey
Courses Plus Student 16,352 Points @if $time == morning {
a {
color: red;
} /* closing 'a' */
@else if $time == afternoon { /* nested inside above 'if', should be at same level */
a {
color: blue
}
}
@else {
a {
color: gray;
}
}
}
}
Hope this helps!
Cheers
Markus Ylisiurunen
15,034 PointsYou have made a small typo. Here is the correct code.
/* Write your SCSS code below. */
@mixin cars ($make, $color) {
.make.#{$make} {
border: 1px solid black;
background-image: url("#{$color}.png");
}
$time: morning;
@if $time == morning {
a {color: red;}
}
@else if $time == afternoon {
a {color: blue;}
}
@else {
a {color: gray;}
}
}
Robert Richey
Courses Plus Student 16,352 PointsThat's pretty close. The code from $time: morning;
on down needs to be outside the mixin to pass the challenge.
Markus Ylisiurunen
15,034 PointsOh okay, I just assumed that it had to be in the mixin since the original question had it in it. I can't check the challenge since I have paused membership :/
Daniele Manca
10,986 PointsHey Robert, I don't think the time variable ought to be placed outside the mixin to pass the challenge, as I tried to do it and didn't work. I get the same error over and over again, which states the the a element's color should be set to red, which is the color they are set to within the code, one of those things I don't get...
Robert Richey
Courses Plus Student 16,352 PointsHi Ben,
The mixin should just have code for styling the interpolated make
class. Link text only needs to be colored once, not each time cars is called.
@mixin cars ($make, $color) {
.#{$make} {
border: 1px solid black;
background-image: url("#{$color}.png");
}
}
Followed by the conditional statements
$time: morning;
@if $time == morning {
a {color: red;}
}
@else if $time == afternoon {
a {color: blue;}
}
@else {
a {color: gray;}
}
Cheers!
Markus Ylisiurunen
15,034 PointsMarkus Ylisiurunen
15,034 PointsCan you format your code a little better. You can see how to do it in Markdown Cheatsheet.