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 trialBorislav Yordanov
4,800 PointsWhy I need to change the places of the if/else if/else ?
const int revenue = 125000; string status = null; private const int _revenue=100000; private const int _revenuee=150000; private const string red="red"; private const string yel="yellow"; private const string gr="green"; if (revenue <_revenue) { status = yel; } else if (revenue < _revenuee { status = yel; } else { status = gr; }
3 Answers
Andrew Winkler
37,739 PointsThe treehouse IDE is picky. Try leaving the 'private' access modifier out. All fields set as private by default in c# so it's the same thing. This worked for me:
const int revenue = 125000;
string status = null;
//replace the magic numbers with constant ints
const int high = 150000;
const int mid = 100000;
//replace the magic words with constant strings
const string red = "red";
const string yellow = "yellow";
const string green = "green";
// keep if/else if/else logic intact
if (revenue < mid)
{
status = red;
}
else if (revenue < high)
{
status = yellow;
}
else
{
status = green;
}
Steven Parker
231,236 PointsI don't understand the question, but your code has three obvious errors:
- "revenue" is defined (as a constant) twice, and assigned to a different value each time.
-
if (revenue < revenue)
"revenue" will never be less than itself -
else if (revenue < _revenuee
this line is missing a closing parenthesis ")"
Borislav Yordanov
4,800 Pointsconst int revenue = 125000; string status = null; private const int revenue1= 100000; private const string red="red"; private const int revenue2= 150000; private const string yellow ="yellow"; private const string green="green"; if (revenue <revenue1 ) { status = red; } else if (revenue < revenue2) { status = yellow; } else { status = green; } and the Bummer is : Did you change the structure of the if/elses if /else statement