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

Melquisedec da Silva
Melquisedec da Silva
1,132 Points

I gave up on this, any help?

I've tried all to respond to thid challenge but I was defeated in task 1 of 3, shame!

A little help? I feel that I miss something on this step of the exercise?

Jeremy Hayden
Jeremy Hayden
1,740 Points

Melquisedec, Don't give up! You can conquer this. Just a suggestion. It helps if you paste the wording of the challenge, and the code you have so far. Good luck.

Melquisedec da Silva
Melquisedec da Silva
1,132 Points

Thanks Jeremy Hayden - no worries, I am still in the run, just a bit confused on this challenge, as I've tried all I think I new...but nothig is working..so I am looking for help!

1 Answer

Hi Melquisedec,

Seems like Arrays have come back in vengeance :) . Let me quickly go through the three challenges with brief explanation

1) Declare a String variable named bestSport and initialize it to the first element of the sports array.

I hope declaring a String variable will not be an issue. General syntax String name_to_define
It then says initialize it to the first element of the sports array. This image will give an idea of how arrays works
Arrays
So what seems the first element to us is actually index 0 for array

let me solve the first for you

String[] sports = { "Basketball", "Baseball", "Tennis" };
String bestSport = sports[0];   //first element is index  0 for the array

2) Declare an int variable named numberOfSports and set it to the number of elements in the array using the array's length property.

Pretty straight forward. Declare and int variable and use the length property of the array. Watch the relevant video again if you get stuck in this.

3) Declare a String variable named lastSport and initialize it with the last element of the sports array

There are two ways to do this. I guess the first will be easy now if you refer to the first example. So last elements will be index ?

I dont want to confuse you more on this. So if you finish the challenge let me know i'll give you the second way too.

Hope this helps

Melquisedec da Silva
Melquisedec da Silva
1,132 Points

Great Hattar, Do you know I am sure that I've tried that before (task 1), but only now it works! hum hum!

The task 2, took me sometime to use the simple way, I was always trying to creat some previous reference and it was not working, finaly I went straight to the point.

The third one was easy!

Thanks! I did it all!!