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 trialCarlos Mendez
2,646 PointsIn the editor we have a dictionary that contains a three letter country code as a key and that country's capital city as
What am I doing wrong?? 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 (key, value) in world { // Enter your code below switch (key, value) { case "BEL", "LIE", "BGR": europeanCapitals.append(value) case "IND", "VNM": asianCapitals.append(value) default: otherCapitals.append(value)
}
// End code
}
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 (key, value) in world {
// Enter your code below
switch (key, value) {
case "BEL", "LIE", "BGR": europeanCapitals.append(value)
case "IND", "VNM": asianCapitals.append(value)
default: otherCapitals.append(value)
}
// End code
}
3 Answers
Steven Parker
231,248 PointsYour only issue is passing two arguments to "switch" when it expects only one (the key).
Note that while Jakob's code will pass the challenge, it deviates a bit from what the instructions asked for.
Your original code (once fixed) is a more correct solution.
Jakub Homik
3,500 PointsYou are right! :) Thanks for that. Default statment in switch could be exaclty like Carlos wrote :)
Cheers!
Carlos Mendez
2,646 PointsThat worked! thanks guys! for some reason, anything loop related has been harder to grasp.
Steven Parker
231,248 PointsCarlos Mendez — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!
Joseph Hines
3,283 PointsThanks for this explanation I was having the hardest time as well. The loop section has been really hard. I've gotten so close and these 1 or two little things have prevented me from fully completing it! It makes a little more sense now. I will go back and read up on this section in the swift notes that Pasan provides!
Jakub Homik
3,500 PointsJakub Homik
3,500 PointsHey Carlos!
You need to change some information in switch statment. You are looking only for a "key" in the world array of dictionary. So you dont need to search for a value. Also the array with otherCapitals are the capitals that not match to Asian or European capitals i.e: "USA", "MEX", "BRA", so your code should look like this:
Let me know if this worked for you :)
Cheers