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 trialSmita Sahoo
864 PointsReplace the magic numbers and strings in the if / else if / else statement with constants.
What's the issue with this code. Could someone respond please?
Thanks, Smita
const int revenue = 125000;
const int lowRevenue = 100000;
const int mediumRevenue = 150000;
const string red = Red;
const string yellow = Yellow;
const string green = Green;
public string status = null;
if (revenue < lowRevenue)
{
status = red;
}
else if (revenue < mediumRevenue)
{
status = yellow;
}
else
{
status = green;
}
3 Answers
Kristian Gausel
14,661 PointsYour only problem seems to be here:
const string red = Red;
const string yellow = Yellow;
const string green = Green;
Which you need to do something like this for:
const string red = "red";
const string yellow = "yellow";
const string green = "green";
Also remove public from
public string status = null;
Noah Yasskin
23,947 Pointsmy answer:
const int revenue = 125000;
const int redLine = 100000;
const int yellowLine = 150000;
string status = null;
const string codeRed = "red";
const string codeYellow = "yellow";
const string codeGreen = "green";
if (revenue < redLine)
{
status = codeRed;
}
else if (revenue < yellowLine)
{
status = codeYellow;
}
else
{
status = codeGreen;
}
Elfar Oliver
3,924 Pointsconst int revenue = 125000; string status = null;
const int lowRevenue = 100000; const string red = "red";
const int highRevenue = 150000; const string yellow = "yellow";
const string _else = "green";
if (revenue < lowRevenue) { status = red; } else if (revenue < highRevenue) { status = yellow; } else { status = _else; }
i6ze5srftzgi8o5iu46z5etr
6,931 Pointsi6ze5srftzgi8o5iu46z5etr
6,931 Points