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

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