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 trialStuart Walker
4,649 PointsNeed assistance with swift statement challenge. It's driving me crazy!
I can't see what else I need to add to this code in order for it to pass the challenge. Any help would be much appreciated
var europeanCapitals: [String] = []
var asianCapitals: [String] = []
var otherCapitals: [String] = []
let world = [
"BEL": "Brussels",
"LIE": "Vaduz",
"BGR": "Sofia",
"USA": "Washington D.C.",
"MEX": "Mexico City",
"BRA": "Brasilia",
"IND": "New Delhi",
"VNM": "Hanoi"]
for (capitalCity) in world {
// Enter your code below
switch capitalCity {
case "BEL", "LIE", "BGR": europeanCapitals.append(not the key!)
case "IND", "VNM": asianCapitals.append()
default: otherCaptials.append()
}
}
2 Answers
Nathan Tallack
22,160 PointsYou were quite close. Consider the changes to your code below.
for cityCode, cityName in world { // This is a dictionary so uses key, value pairs.
switch cityCode {
case "BEL", "LIE", "BGR": europeanCapitals.append(cityName)
case "IND", "VNM": asianCapitals.append(cityName)
default: otherCaptials.append(cityName)
}
}
Stuart Walker
4,649 PointsOk I got it to work. Thanks for your help Nathan!
Stuart Walker
4,649 PointsStuart Walker
4,649 PointsStill can't seem to pass the challenge. Not quite sure what to do next.
Nathan Tallack
22,160 PointsNathan Tallack
22,160 PointsRighto. So let's simplify what you need to input, and understand it. :)
You already have all the code there in a fresh challenge screen. Be sure to reload it in your browser so that it is fresh.
Just like this:
// Enter your code below
// Enter your code above
Stuart Walker
4,649 PointsStuart Walker
4,649 PointsOk I got it to work. Thanks for your help Nathan!