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 trialRenan Coutinho
1,373 PointsDeclare (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?
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);
2 Answers
Andrew Dummer
6,885 PointsYou 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;
.
Renan Coutinho
1,373 PointsThanks u =D
Justin Kraft
26,327 PointsJustin Kraft
26,327 PointsThe 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;