Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Coding the Fun Facts Using an Array

Renan Coutinho
Renan Coutinho
1,373 Points

Declare (AKA create) an int variable named numberOfSports and set it to the number of elements in the array using the ar

What i am missing?

Array.java
String[] sports = { "Basketball", "Baseball", "Tennis" };

String bestSport = sports[0];

Random randomGenerator =  new Random();
int numberOfSports = randomGenerator.nextInt(sports.length);

sports = bestSports [numberOfSports];
        return sports;


And i tried it

String[] sports = { "Basketball", "Baseball", "Tennis" };

String bestSport = sports[0];

int numberOfSports = randomGenerator.nextInt(sports.length);
Justin Kraft
Justin Kraft
26,327 Points

The challenge simply asks to store the number of sports in an int variable you declare. This is done by using the length property associated with arrays as follows:

int numberOfSports = sports.length;

2 Answers

You don't need to reference randomNumberGenerator in this quiz, that is just part of the video. Simplify your last line to int numberOfSports = sports.length;.