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 trialDickson Cheung
2,573 PointsNil Value in Collections - Challenge
i'm having problems with this challenge
let movieDictionary = ["Spectre": ["cast": ["Daniel Craig", "Christoph Waltz", "Léa Seydoux", "Ralph Fiennes", "Monica Bellucci", "Naomie Harris"]]]
var leadActor: String = ""
// Enter code below if let movie = movieDictionary["Spectre"], let castList = movie["cast"] { let leadActor = castList[0] }
I'm trying to pull Daniel Craig's name but everytime i run the program I'm getting Error: Make sure you are calling array [0] - there's no compiler error so i'm not sure where i'm going wrong here
let movieDictionary = ["Spectre": ["cast": ["Daniel Craig", "Christoph Waltz", "Léa Seydoux", "Ralph Fiennes", "Monica Bellucci", "Naomie Harris"]]]
var leadActor: String = ""
// Enter code below
if let movie = movieDictionary["Spectre"],
let castList = movie["cast"] {
let leadActor = castList[0]
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, Dickson! You're doing just fine. You have one extraneous let
. The variable leadActor
is already set up for you so you just need to reassign the appropriate string. Long story short? Remove the let
before leadActor
and your code passes!
Hope this helps!
Dickson Cheung
2,573 PointsDickson Cheung
2,573 PointsThanks Jennifer!