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 trialkrishna allu
745 PointsI cant able to find the error.
Help me to find error?
int value = int.Parse(Console.ReadLine());
if(value < 0 || value >20)
{
Console.WriteLine(string.Format("You entered {0}",value));
}
else
{
throw new System.Exception("Outside of the Range");
}
1 Answer
andren
28,558 PointsYour code is right but the logic is off, or reversed more accurately. The challenge wants the exception to be thrown if the value is less than 0 or greater than 20. Your code throws the exception if the value is not less than 0 or greater than 20.
If you swap the code in your else block with the code in your if block like this:
int value = int.Parse(Console.ReadLine());
if(value < 0 || value >20)
{
throw new System.Exception("Outside of the Range");
}
else
{
Console.WriteLine(string.Format("You entered {0}",value));
}
Then your code will pass.
krishna allu
745 Pointskrishna allu
745 PointsThank you