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 trialTravis Williams
2,049 PointsIt wont work and i have been trying for a long time
I don't know can someone point me in the right direction
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
bool reach;
if ( distanceToFly <= tongueLength)
{
reach = true;
}
else ()
{
reach = false;
}
return reach;
}
}
}
1 Answer
Antonio De Rose
20,885 Points//the approach is fine, almost there
//if not for 2 mistakes
namespace Treehouse.CodeChallenges
{
class Frog
{
public readonly int TongueLength;
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
public bool EatFly(int distanceToFly)
{
bool reach;
if ( distanceToFly <= tongueLength) //error number 1, can you access tongueLength,
//it has got a different scoping, that is of a different function,
//you cannot access a variable which is residing in a different function,
//but you can access the property / variable which is mentioned, just after the class Frog
{
reach = true;
}
else () //error number 2, why do you need parenthesis, just after else
{
reach = false;
}
return reach;
}
}
}
abhijeet Pednekar
758 Pointsabhijeet Pednekar
758 PointsYou have to put TongueLength because it is global and can be used anywhere inside the class. and you have to remove the parenthesis at the end of else.