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 trialMichael North
2,561 PointsI'm just stuck
In this question I am just drawing a blank, and I have no idea what to do. Can I please get some help?
namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
for(int i = 0; )
}
}
}
namespace Treehouse.CodeChallenges
{
public class Frog
{
public int TongueLength { get; }
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
}
}
2 Answers
Steven Parker
231,236 PointsHere's a few hints:
- your for loop still needs the condition and increment expressions
- for the condition, you might compare the index with the length of the frogs array
- the increment expression is typically either "
i += 1
" or "i++
" - before your loop, you may want to declare a variable for summing the tongue lengths
- inside the loop, you could add each frog's tongue length to your total
- after the loop, you could return the total divided by the number of frogs (length of array)
Can you get it now?
Jon Wood
9,884 PointsThe challenge is asking to get the average of the each frog's tongue length. You're off to a great start by starting a for loop. :)
You may remember from the video that the array object has a Length
property, so you can use that in your for loop to tell how many times to iterate. Remember, though, array indexes are zero based, so that would need to be taken into account otherwise you'd get an [IndexOutOfRangeException](http://stackoverflow.com/a/20940980/186013)
.
Once in the for loop, you can use a variable to keep track of adding each tongue length, then to take the average, just divide that by how many items are in the array (remember the Length
property here again).
Hope that helps! Let me know if you need some more hints, though.