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 trialCaleb Kleveter
Treehouse Moderator 37,862 PointsHow do this this challenge work?
How does the Working with Switch Statements CC work? I tried some code, but it caused a bunch of errors (it got deleted when I accidentally clicked on a link). The instructions are rather long, so I suggest looking a the challenge. I don't have a remote idea of how to do the challenge.
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
// End code
}
3 Answers
Pasan Premaratne
Treehouse TeacherActually Jacob Dobson is correct here. "BRA" returns "Brasilia" which is the capital city of Brazil. There was a bug in the challenge editor which allowed you to pass the question with the above answer.
The correct answer means no BRA in europeanCapitals and you need to include New Delhi in Asia.
Sorry for the confusion everyone!
Richard Lu
20,185 PointsHey Caleb,
In this challenge, I think what Pasan Premaratne wants us to do is practice using switch statements. Here's how I went about it.
for (key, value) in world {
switch key {
case "BEL", "BGR", "BRA": europeanCapitals.append(value)
case "VNM": asianCapitals.append(value)
default: otherCapitals.append(value)
}
}
Caleb Kleveter
Treehouse Moderator 37,862 PointsThat makes sense now. Thanks!
Jacob Dobson
5,122 PointsHow come you don't use all of the capitals? Why "BEL", "BGR", and "BRA" for europeanCapitals? Brazil is not in Europe, either... and isn't India in Asia, too?
Richard Lu
20,185 PointsHey Jacob,
The reason why I do not use the rest of the values in the dictionary is because they are satisfied in the default case. To answer your second question, he provides the values for what the acronyms stand for in the follow dictionary:
let world = [
"BEL": "Brussels", // european capital
"LIE": "Vaduz",
"BGR": "Sofia", // european capital
"USA": "Washington D.C.",
"MEX": "Mexico City",
"BRA": "Brasilia", // european capital
"IND": "New Delhi",
"VNM": "Hanoi"
]
Good luck! :)
- Rich
Pasan Premaratne
Treehouse TeacherActually Jacob Dobson is correct here. "BRA" returns "Brasilia" which is the capital city of Brazil. There was a bug in the challenge editor which allowed you to pass the question with the above answer.
The correct answer means no BRA in europeanCapitals and you need to include New Delhi in Asia.
Sorry for the confusion everyone!
Shandas Duchintav
8,222 PointsGotta remove my question. Awesome.
Richard Lu
20,185 PointsRichard Lu
20,185 PointsOh cool, thanks for pointing that out Pasan Premaratne. I'm learning something new everyday. Cheers :)