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

Brent Stewart
Brent Stewart
371 Points

Initializing variable in an array

Cannot figure out the following test, maybe I am overthinking, which I tend to do. But I have written so many different formulas and cannot figure this one out. Here is the question...

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

the following is the code already provided...

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

3 Answers

Damien Watson
Damien Watson
27,419 Points

Hi Brent,

So, create a string and set it to the first element of sports, would be something like:

String bestSport = sports[0];
Brent Stewart
Brent Stewart
371 Points

Thanks for the quick reply, however tried that code already and its not right. Im thinking has something to do with the "int" command?

Brent Stewart
Brent Stewart
371 Points

Ok so I have figured it out, the string variable is actually "bestSport" not "bestSports". Ive been stuck on this for 2 days just because I added the "s" to make it plural lol.

Damien Watson
Damien Watson
27,419 Points

Ah cool, glad to hear. I'll adjust my response incase someone else in trouble finds this post. Also I think you can link to the challenge, which may help get a quicker response. Cheers, :)