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 Loops and Final Touches Constants

Xinyu (Sean) Zhang
PLUS
Xinyu (Sean) Zhang
Courses Plus Student 7,064 Points

What does it mean define const red? I have already done it! This is not very descriptive question!

Why?

CodeChallenge.cs
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

It'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
Steven Parker
231,198 Points

:x: He can't use the name red for the string because it's already assigned to the numeric value.

Good catch there Steven. Time for bed for me. :)

Steven Parker
Steven Parker
231,198 Points

:point_right: You're halfway there!

You have replaced all the numeric values with constants, so far, so good! :+1:

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.