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 trialSadettin Senberber
974 PointsHow can I add the boolean expression in this code?
In this instance should I write "public bool(xx xxx)" expression or like "bool a = true" expression. What I suppose to do? Thank you.
int value = -1;
string textColor = null;
return ((value < 0) = textColor = "red") ? textColor = "green";
1 Answer
Steven Parker
231,198 PointsThe instructions say to " Use a ternary if statement instead of an if/else statement to initialize the textColor variable". You won't need to add a new boolean expression, though you'll probably want to re-use the one that was originally in the "if" statement.
You also won't need a "return", those are only valid inside functions anyway.
Without providing an explicit spoiler, an assignment using a ternary might have this basic structure:
variable = (expression) ? true-value : false-value;