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 trialANDREA HEMPHILL
14,484 PointsHelp with Java Code Challenge!
Can anyone give me a hint as to what I am missing for this challenge. It asks that I return a map that lists video title, and video. Then I got an error that said "Expected 0 keys, returned 23". Shouldn't I be returning keys if the videos need titles? I am at a wall as to why this doesn't work.
Also there weren't any compiler errors, I just didn't do the challenge correctly.
public Map<String, Video> videosByTitle(Course course) {
Map<String, Video> videoMap = new HashMap<>();
List<Video> vList = course.getVideos();
Video aVideo;
while(!vList.isEmpty()){ //while there are still videos in the list
aVideo = vList.remove(0); // remove the first video
videoMap.put(aVideo.getTitle(), aVideo); // get that video's title and add it to the map, with the video.
}
return videoMap;
}
}
1 Answer
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey there you successfully set up your VideoMap and videoList approriately.
However I think the trouble the trouble if trying to remove the video First. an easier way to do this would be for an enhanced for loop and just go through the videos. Try something like.
for (Video video : vList) {
VideoMap.put(video.getTitle(), video);
}
Would set you up nicely, let me know if this doesn't help.
ANDREA HEMPHILL
14,484 PointsANDREA HEMPHILL
14,484 PointsThank you, that did help. I really needed to understand my error.