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 trialGaurang Kotasthane
1,394 Pointsreturn choice -1
I did not understand why we returned choice as -1 any help would be appreciated thanks
1 Answer
Matthias Margot
7,236 PointsYou know how in the console user interface the artists and songs to choose from are ordered from 1 to (total number of artists)? This is starting at '1' problem is indices (plural of index) in coding start at 0. So if you choose the seconds artist your choice is '2' but the index of the artist in the ArrayList (or whatever collection you're using, been a while since i watched that video, might be a map don't remember) is actually not '2' but 2 - 1 which is '1'. The second entry in your list has the index '1' because the first entry has the index '0' so that's why you take 1 away from choice.
Gaurang Kotasthane
1,394 PointsGaurang Kotasthane
1,394 Pointsoh now it makes sense!