
Dalin Nkulu
15,587 Pointsforeach loop challenge: i don't understand the conditional statement
in the conditional statement what is the 3 "frog" for me the first "Frog" is the class the second ("frog") act as a counter the third it the object of the class
why "frogs.TongueLength" do not work but "frog.TongueLength" will work
namespace Treehouse.CodeChallenges
{
class FrogStats
{
public static double GetAverageTongueLength(Frog[] frogs)
{
double average = 0.0;
foreach(Frog frog in frogs)
{
average = frogs.TongueLength;
}
return average/frogs.Lenght;
}
}
}
namespace Treehouse.CodeChallenges
{
public class Frog
{
public int TongueLength { get; }
public Frog(int tongueLength)
{
TongueLength = tongueLength;
}
}
}
2 Answers

Brendan Whiting
Front End Web Development Treehouse Moderator 84,129 Pointsfrog
is a variable of type Frog
, which is a class that has a TongueLength
property.
frogs
is a variable of type Frog[]
, a list of frogs. Lists don't have TongueLength
, individual frogs in the list do.
Try iterating through all the lists and calculating a sum of tongue lengths, and then dividing that sum by the number of frogs in the list.

Dalin Nkulu
15,587 Pointshey Brendan are you on social media? if yes what your handle?