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 trialyujia liu
14,964 Pointsi do not know why my answer is wrong
int value = -1; string textColor = null;
(value < 0)?textColor = "red":textColor = "green"; }
Here is my code , I just change if else statement to ternary if. I cannot find out why is wrong.
int value = -1;
string textColor = null;
(value < 0)?textColor = "red":textColor = "green";
}
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! You're doing fine, and made it quite a ways so far. But it seems you've managed to get the order of things a bit mixed up here.
textColor = (value < 0) ? "red" : "green";
Here, we're looking at the value. The variable for which you're changing the value based on the condition needs to be at the far left. Remember, this is after all an assignment. Now, if the value is less than 0 we'll assign "red" to textColor. Otherwise, we assign the value "green". Hope this helps!
yujia liu
14,964 Pointsok. Now I understand. Thank you.