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 trialXinyu (Sean) Zhang
Courses Plus Student 7,064 PointsWhat does it mean define const red? I have already done it! This is not very descriptive question!
Why?
const int revenue = 125000;
const int red = 100000;
const int yellow = 150000;
string status = null;
if (revenue < red)
{
status = "red";
}
else if (revenue < yellow)
{
status = "yellow";
}
else
{
status = "green";
}
2 Answers
Edward Ries
7,388 PointsIt's wanting you to remove the string literals from the code by placing them as const strings at the top.
const string red= "red";
Then in code you can reference:
status = red;
Steven Parker
231,275 PointsYou're halfway there!
You have replaced all the numeric values with constants, so far, so good!
But now you need to the same thing with the string constants. For example for red you might have:
const string redColor = "red";
And then later, when the status is assigned, you might have:
status = redColor ;
Do that for all the color names and you should have it.
Steven Parker
231,275 PointsSteven Parker
231,275 PointsHe can't use the name red for the string because it's already assigned to the numeric value.
Edward Ries
7,388 PointsEdward Ries
7,388 PointsGood catch there Steven. Time for bed for me. :)