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

I am stuck at the ternary if coding challenge because the 'code checking algorithm' doesn't recognize the solution

Even though my solution is correct I am always getting the error: Bummer! Did you include the "red" and "green" string literal expressions (separated by a colon) to the right of the ternary operator?

Can anybody help me fix this?

CodeChallenge.cs
int value = -1;
string textColor = (value < 0) ? textColor = "red" : textColor = "green";

1 Answer

I managed to find the solution it turns out its: int value = -1; string textColor = (value < 0) ? "red" : "green"; Its pretty obvious since the challenge asks to initialize the textColor variable to red or green and not to set it. They should definitely change the error message though.