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

Scott Tucker
Scott Tucker
3,765 Points

How is this code not being accepted?

I really don't understand how this code is not getting accepted. The constants are set and I used them in the if/else statement. When I go and check work, it asks me if I have deleted the revenue variable declaration, but I have. Unless it is playing mind games with me and actually needs revenue to be declared. Any help would be really appreciated as this has been the second time today that I have been generally stuck with these tasks.

CodeChallenge.cs
const int red = 100000;
const int yellow = 150000;

const string rR = "red";
const string yR = "yellow";
const string gR = "green";

if (red)
{
    rR;
}
else if (yellow)
{
    yR;
}
else
{
    gR;
}

1 Answer

Steven Parker
Steven Parker
231,269 Points

You did create all the required constants, but instead of integrating them into the expressions by replacing the literals, you replaced the entire expressions with them.

:point_right: You still need the expressions that perform the comparisons and make the assignments:


:warning: SPOILER ALERT


CodeChallenge.cs
const int revenue = 125000;
const int red = 100000;
const int yellow = 150000;

const string rR = "red";
const string yR = "yellow";
const string gR = "green";

string status = null;

if (revenue < red)
{
    status = rR;
}
else if (revenue < yellow)
{
    status = yR;
}
else
{
    status = gR;
}
Scott Tucker
Scott Tucker
3,765 Points

Thank you! Your last sentence actually pushed me forward to getting it right. I knew I was understanding it but I just didn't have it laid out correctly.