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

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,364 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 ...

Grigorij

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,364 Points

Hmmmm,

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 :)