 # Return the average length of the tongues of the frogs in the array. Use a foreach loop as part of your solution.

I'm ashamed to say i'm completely lost. I've looked at this for ages. re-watched the video time and time again and i still can't fathom it u.u

Would anyone be willing to explain to me how this works exactly? namespace Treehouse.CodeChallenges { class FrogStats { public static double GetAverageTongueLength(Frog[] frogs) { double total = 0;

```        foreach(Frog frog in frogs)
{
total+=frog.TongueLength;
}
}
}
```

} ```        public static double GetAverageTongueLength(Frog[] frogs)
{

Frog frog = new Frog(7);
int sum = 0;
int count = 0;

foreach(Frog f in frogs)
{
sum += f.TongueLength;
count++;
}

int avg = sum / count;
return avg;

}
```

What's the reason for creating a new Frog at the beginning of the method? Other than that, the only change I'd suggest is getting rid of the avg variable for efficiency, since you only use it once. Instead, you could just return sum / count.

Is it ok if I share a correct code? (question to Treehouse Forum admins) I am so happy to solve that I can't hold myself from sharing. Because there are cases where I couldn't find a correct answer in Treehouse forum and it makes me struggle.

```namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
double total = 0;
foreach(Frog frog in frogs)
{
total += frog.TongueLength;
}
}
}
}
``` You know how to do an average, right? You add up all the values and then divide by the number of things.

In this case, the "things" are the frog tongues and the values are the tongue lengths.

Your function is going to get a list of Frog objects. In this list, every Frog has a TongueLength. So if you create a loop that takes each one and adds it to a total, and then after the loop divides it by the number of Frogs, you'd have an average length.

Do you have a better idea about what to do now? I did not quite understand a few basic things... please keep in mind that I will start this whole course again as well as going through the basis again, but I get very confused when I see using variables that we did not initialize in a way that I understand: For example, I get the meaning of the foreach loop, but in anil rahman's code where did the "f" come from? I will study more but a quick answer would be much appeciated Sorry for the silly doubt I believe you can skip out the count variable altogether here and just use "frogs.Length" for the size of the array.

With regards to the f question, I'm still learning and know more in the VBA world but I believe it's just a placeholder name so you can reference the Frog within the loop and won't be used outside the loop. So could easily have also said,

foreach(Frog kermit in frogs)

or could have said,

foreach(Frog meh in frogs)

as long as you then said kermit.TongueLength or meh.TongueLength respectively.

My question is: where does this .TongueLength come from in the body of the loop. The function's name is GetAverageTongueLength. Try this answer it will work

``` double total=0;
for(int i=0;i<frogs.Length;i++)
{
total+=frogs[i].TongueLength;
}
This answer would not work because it is supposed to be a `foreach` loop.