Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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