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 trialJose Badillo
1,186 Pointsuse bool expression to evaluate.
so I'm doing c# oop and I got to the ternery if expression and in the quiz its asking to use trynery to initialize value of the string textColor iv wrote the expression multiple different ways witch all did compile when I used the repl and gave me outputs correctly so I don't understand what they are asking me to do here any help plesse
int value = -1;
string textColor = null;
(value) ? textColor = "red" :(value >= 0) ? textColor "green";
(value < 0) ? textColor = "red" : textColor = "green";
if (value < 0)
{
textColor = "red";
}
else
{
textColor = "green";
}
1 Answer
Steven Parker
231,269 PointsDon't include assignments inside the ternary expression. Use the entire ternary as the right side of an assignment statement. A typical assignment with a ternary has this form:
- variable = ( conditional_expression ) ? value_if_true : value_if_false ;
And be sure to remove the original "if" code when you replace it with the ternary assignment.