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 trial

C# C# Objects Encapsulation and Arrays Ternary If

Jose Perez
Jose Perez
1,338 Points

don't know where to add Boolean to evaluate

int value = -1; string textColor = null;

(value < 0) ? textColor = "red" : textColor = "green";

CodeChallenge.cs
int value = -1;
string textColor = null;

(value < 0) ? textColor = "red" : textColor = "green";

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing great, and this trips up a lot of people. On the plus side, you've got all the components, but they're a little out of order.

First, we say what we want to happen, then we give the condition, and then we give the two alternatives. Take a look:

textColor = (value < 0) ? "red" : "green";

In the first part, we say that we want a color assigned to textColor. Next, we give the expression this should be dependent upon. And lastly, we say the two alternatives. The first one will be what happens when the expression evaluates to true and the second is what happens if it evaluates to false. So the textColor = is the thing that "happens". The (value < 0) is the expression that's being evaluated. Then we insert a question mark. The thing on the left of the colon is the value assigned if it's true. The thing on the right is the value assigned if it is false.

Hope this helps! :sparkles:

Jose Perez
Jose Perez
1,338 Points

thanks it really did help