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 trialJoe Nelson
1,331 PointsNot sure what Im doing wrong on this one
I keep getting a message saying to make sure I am capturing all asian capitals. Im not sure what I'm doing wrong?
var europeanCapitals: [String] = []
var asianCapitals: [String] = []
var otherCapitals: [String] = []
let world = [
"BEL": "Brussels",
"LIE": "Vaduz",
"BGR": "Sofia",
"USA": "Washing D.C",
"MEX": "Mexico City",
"BRA": "Brasilia",
"IND": "New Dehli",
"VNM": "Hanoi"]
for (key, value) in world {
switch key {
case "BEL", "Brussels", "LIE", "Vaduz", "BGR", "Sofia": europeanCapitals.append(value)
case "IND", "New Dehli", "VNM", "Hanoi": asianCapitals.append(value)
case "MEX", "Mexico City", "USA", "United States", "BRA", "Brasilia": otherCapitals.append(value)
default: print("I dont know that one!")
}
}
2 Answers
Steven Deutsch
21,046 PointsHey Joe Nelson,
Your corrected code is valid. Try placing it between the comment markers to get the solution to pass. As a general rule, don't edit the code provided by the challenge, including the comments.
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 {
case "BEL", "LIE", "BGR":
europeanCapitals.append(value)
case "IND", "VNM":
asianCapitals.append(value)
default:
otherCapitals.append(value)
}
// End code
}
Good Luck
Jennifer Nordell
Treehouse TeacherYou are by far the first to get stuck on this challenge! In fact, I answered this question not long ago at all. Here you can see my full answer and an explanation. https://teamtreehouse.com/community/i-dont-know-what-to-do-or-why-im-wrong
Joe Nelson
1,331 PointsI think there may be a bug because I am still getting the same response. Here is the new code, which is identical to yours.
var europeanCapitals: [String] = []
var asianCapitals: [String] = []
var otherCapitals: [String] = []
let world = [
"BEL": "Brussels", // europe
"LIE": "Vaduz", // europe
"BGR": "Sofia", // europe
"USA": "Washing D.C", // other
"MEX": "Mexico City", // other
"BRA": "Brasilia", // other
"IND": "New Dehli", // asia
"VNM": "Hanoi" // asia
]
for (key, value) in world {
switch key {
case "BEL", "LIE", "BGR":
europeanCapitals.append(value)
case "IND", "VNM":
asianCapitals.append(value)
default:
otherCapitals.append(value)
}
}
Joe Nelson
1,331 PointsJoe Nelson
1,331 Pointsahhh thank you! That solved it