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

Nodir Musaev
Nodir Musaev
843 Points

Cant solve this array task for android

Would really appreciate the help! Thanks.

2 Answers

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Nodir,

I commented the challenge a little:

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

// TASK 1:
String bestSport = sports[0];
// here you are creating a new String variable "bestSport"
// then you assigning a value to this new String variable
// this value is the first String ("Basketball") from the array above
// arrays are zero based, so every String inside the array is counted from 0 to ....
// so "Basketball" is count 0
// "Baseball" is count 1
// and "Tennis"  is count 2 
// and so on

// TASK 2:
int numberOfSports = sports.length;
// here you are creating a second variable
// it is a Integer (int) so it stores numbers
// the method length (no parenthesis) can be used on arrays
// and our array is called sports
// so sports.length; returns a number 3 (three Strings inside the array)
// and stores it inside our numberOfSports variable that takes a number of elements inside the sports array.

String lastSport = sports[2];
// so the last String inside the array is on place 2

I hope my explanations help you understand the challenge a little bit more. Let me know if you need more help ...


Nodir Musaev
Nodir Musaev
843 Points

Yes I understood it but there must have been a glitch because when I submitted this exact code it kept coming up as an error. Then when I copied and pasted a code from the forum that was exactly the same, it worked for some reason. Thanks anyway!

Grigorij Schleifer
Grigorij Schleifer
10,365 Points


this it really weard ... But do you understand the logic? Then I would say, everething is fine :)))))

Nodir Musaev
Nodir Musaev
843 Points

Yeah I understand it thanks for the pretty descriptive comments too :)