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 trialLeo Ngai
2,184 PointsCan anyone give me some help? Very much appreciated! PS. The interactive learning experience at Tree Hosue is great!
Help. Thanks!
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
bool canEat;
if (distanceToFly < = TongueLength)
{
canEat = true;
}
else
{
canEat = false;
}
return canEat;
}
}
}
2 Answers
Steven Parker
231,236 PointsYou just have a typo.
The "less than or equal" operator should be written as <= , with no space between the symbols.
Also, while your solution is perfectly functional as is (once repaired), you could take advantage of the fact that a conditional expression can be used as a boolean value itself, and condense the method code to a single statement:
return distanceToFly <= TongueLength;
Leo Ngai
2,184 PointsThanks! Your suggestion resolved my quesion! Cheers!