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 trial

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;.