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!
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

Narisorn Yossaravas
600 PointsNot working? int value = -1;string textColor = null; return (value < 0) ? textColor = "red" : textColor = "green";
I don't understand why my Ternary If codes below won't compile. Help please...
int value = -1; string textColor = null; return (value < 0) ? textColor = "red" : textColor = "green";
int value = -1;
string textColor = null;
return value < 0 ? textColor = "red" : textColor = "green";
1 Answer

Jennifer Nordell
Treehouse TeacherHi there! You have all the parts present but they're all a bit out of order. Also, the challenge is not asking you to return anything rather set the value of a variable.
So let's go through the steps of a ternary. First, we say what variable we're going to assign a value to. Then we say what expression we're basing our decision on. Finally, we give the two options with the first one being what happens if it evaluates to true and the second one if it is false. Take a look:
// textColor is the variable we're going to assign something to
// value < 0 is the expression we're checking
// if the value is less than 0 the value "red" will be assigned to textColor
// otherwise the value "green" will be assigned to textColor
textColor = (value < 0) ? "red" : "green";
Hope this helps!
Narisorn Yossaravas
600 PointsNarisorn Yossaravas
600 PointsThanks you! The code is now working.