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 trialMUZ140984 Tatenda Mangoro
5,631 Pointsdeclaring arrays
having challenges declaring an array, followed the instructions in the video, but not sure where am getting it wrong
2 Answers
Steve Hunter
57,712 PointsHi there,
To declare an array we use the square brackets []
. So, declaring an array of String
variables we would say:
String [] anArray;
The challenge wants it to be called sports
so let's change that to:
String [] sports;
We then need to initialise the array by assigning three values to it. The challenge reminds you about the curly braces, helpfully. So, adding to the above, we open the curly brackets, then add three strings (preferably names of sports!) and separate them with commas:
String [] sports = {"football", "rugby", "squash"};
Making sure to close the curly braces and end the line with a semi-colon, and that should be good to go!
Hope that helps.
Steve.
Alice Emmely Sadza
4,205 Pointsthank you Steve..
MUZ140984 Tatenda Mangoro
5,631 Pointsthank you guys for the help. it worked
Steve Hunter
57,712 PointsNo problem - glad it worked for you. :-)
Steve.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsAlice Emmely Sadza link