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 trialHamzah Iqbal
Full Stack JavaScript Techdegree Student 11,145 PointsReturn the average length of the tongues of the frogs in the array. Use a for loop as part of your solution.
I'm stuck in deep. I've tried figuring out what's wrong but nothing comes up my mind.
namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
int frogToungeLength = 0;
int frogTotal = 0;
for(int i=0; i < frogs.Length; i++)
{
frogTongueLength = frogs[i].TongueLength;
frogTotal++;
}
return frogToungeLength/frogTotal;
}
}
}
namespace Treehouse.CodeChallenges
{
public class Frog
{
public int TongueLength { get; }
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
}
}
2 Answers
Steven Parker
231,275 PointsDid you try the "preview" button? When you do, the compiler message shown is:
FrogStats.cs(11,16): error CS0103: The name `frogTongueLength' does not exist in the current context
And that's because on line 7 where it is declared, it is spelled differently ("frogToungeLength").
Hamzah Iqbal
Full Stack JavaScript Techdegree Student 11,145 PointsSteven Parker , yes. But it is still giving me the same error. Nothing is shown under "Editor".
namespace Treehouse.CodeChallenges { class FrogStats { public static double GetAverageTongueLength(Frog[] frogs) {
int frogTongueLength = 0;
int frogTotal = 0;
for(int i=0; i < frogs.Length; i++)
{
frogTongueLength = frogs[i].TongueLength;
frogTotal++;
}
return frogTongueLength/frogTotal;
}
}
}
Steven Parker
231,275 PointsThis code is just storing the last last tongue length. Change the "=" to "+=" to make it sum them instead.
Hamzah Iqbal
Full Stack JavaScript Techdegree Student 11,145 PointsHamzah Iqbal
Full Stack JavaScript Techdegree Student 11,145 PointsI've just fixed it, however I still receive an error: "Are you returning the average length of the tongues of the frogs in the array?"
Steven Parker
231,275 PointsSteven Parker
231,275 PointsDid you make sure the spelling is the same in all the references? (if that's not it, show the current code)