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 trialIryna Bondarenko
777 PointsI think, my code is correct but it's not accepted. Hints don't help
What is wrong here?
int value = -1;
string textColor = null;
(value < 0) ? textColor = "red" : textColor = "green";
3 Answers
Dane Parchment
Treehouse Moderator 11,077 PointsI believe you need to set the variable equal to the ternary operator...so try this:
int value = -1;
string textColor = null;
textColor = value < 0 ? "red" : "green";
Jennifer Nordell
Treehouse TeacherHi Iryna Bondarenko!
You're doing well! It's just a little out of order. First, we say the name of the variable whose value we're looking to change. Then we give the condition. If it evaluates to true it will change the textColor to red. If it's false, it will change the textColor to green. Take a look at the line you need:
textColor = (value < 0) ? "red" : "green";
This is very handy when we have a variable whose value will be set to one thing if an expression evaluates to true and another if the expression evaluates to false! Good luck!
And Dane Parchment is a fast typer!
Iryna Bondarenko
777 PointsThank you Jennifer!
Cindy Lea
Courses Plus Student 6,497 PointsTry it without the parenthesis for value < 0
Iryna Bondarenko
777 PointsIryna Bondarenko
777 PointsThank you, Dane!