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 trialKacper Gagatek
3,418 Points(loop)The preview says that there is an unexpected "}" at line 9 but there isnt a one anywhere near
I have tried everything now, plz help
namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
double total = 0;
int i = 0;
for(i <= frogs.Length; i++)
{
total += frogs[i];
}
return total/i;
}
}
}
namespace Treehouse.CodeChallenges
{
public class Frog
{
public int TongueLength { get; }
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
}
}
1 Answer
Steven Parker
231,275 PointsThe message is a bit misleading, but it looks like there are 3 issues:
- the "for" loop needs an initialization clause, even if it is empty
- the loop should stop before reaching the array "Length"
- you can't add "frogs", add their tongue lengths instead:
for ( ; i < frogs.Length; i++) // empty init clause, and stop BEFORE Length
{
total += frogs[i].TongueLength; // add lengths not frogs
Kacper Gagatek
3,418 PointsKacper Gagatek
3,418 Pointsnow i see it cropped the line numbers... The line 9 is this --> for(i <= frogs.Length; i++) on the first picture