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 trialMUZ140831 Blessing Funani
654 PointsDeclare a String variable named bestSport and initialize it to the first element of the sports array.
Declare a String variable named bestSport and initialize it to the first element of the sports array.
String[] sports = { "Basketball", "Baseball", "Tennis" };
String[] BestSports = {"football"};
2 Answers
miguelcastro2
Courses Plus Student 6,573 PointsWe access array using the number of the element which always begins at zero. Recall the video and how you access an individual element in an array:
// Our Array
String[] sports = { "Basketball", "Baseball", "Tennis" };
// Access an element in the array
// Basketball
sports[0];
// Baseball
sports[1];
// Tennis
sports[2];
So for our challenge:
Declare a String variable named bestSport:
String bestSport;
initialize it to the first element of the sports array.
String bestSport = sports[0];
MUZ140831 Blessing Funani
654 Pointsstil its giving me a syntax error
miguelcastro2
Courses Plus Student 6,573 PointsPlease paste your complete code. I tested the code I wrote and it works as expected.