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

Rasmus Flomén
Rasmus Flomén
3,193 Points

Help! Code challange "Convert the if/else to a ternary if statement."

Hi, what am I missing?? I get the error "Bummer! Did you include the boolean expression to evaluate" I dont relly understand what is wrong.

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

First we say what variable we're looking at, then we give the expression to evaluate. You've got it a little backwards here.

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

If the value is less than 0 the textColor is set to red, otherwise it's set to green. Hope that's helpful! :smiley:

Rasmus Flomén
Rasmus Flomén
3,193 Points

Thank you Jennifer for the help :)

Luis Santos
Luis Santos
3,566 Points

I was a bit confused with what the instructor explained on the video and what you actually did. I thought I understood the challenge at length but kept getting a bummer message requesting a Boolean expression. Thank you for the easy explanation, Ms. Nordell.

Thanks. But i think the real problem here is how Treehouse expects us to know this sort of thing without sufficient knowledge from the previous material, videos, etc. This isn't the first time I've had to search for a solution out of frustration. The teaching methods aren't intuitive to the learner. Well, in my opinion, at least.

Jesper Henriksen
Jesper Henriksen
3,308 Points

This made me realize that my only error was actually a typo in "green" :D Thank you for the assistance!