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 trialmark hengstebeck
1,119 PointsWill someone provide me with a hint as to what I am missing in this challenge?
Working with switch statements: var europeanCapitals: [String] = ["Brussels", "Vaduz", "Sofia"] var asianCapitals: [String] = ["New Delhi", "Hanoi"] var otherCapitals: [String] = ["Washington D.C.", "Mexico City", "Brasilia"]
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 "VNM" { case "BEL": europeanCapitals case "LIE": europeanCapitals case "BGR": europeanCapitals case "IND": asianCapitals case "VNM": asianCapitals default: otherCapitals } }
var europeanCapitals: [String] = ["Brussels", "Vaduz", "Sofia"]
var asianCapitals: [String] = ["New Delhi", "Hanoi"]
var otherCapitals: [String] = ["Washington D.C.", "Mexico City", "Brasilia"]
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 "VNM" {
case "BEL": europeanCapitals
case "LIE": europeanCapitals
case "BGR": europeanCapitals
case "IND": asianCapitals
case "VNM": asianCapitals
default: otherCapitals
}
}
2 Answers
William Li
Courses Plus Student 26,868 PointsHi there.
The idea of the switch
statement is do case comparison with the key, therefore, the value to consider is key, not "VNM". You need to change the switch line to switch key {
Secondly, the rest of your case statement look mostly ok, but you forgot to append the value to the appropriate Array. For example, for the case "BEL"
here's the correct way of writing it.
switch key {
case "BEL": europeanCapitals.append(value)
....
....
}
Do so for every line of the case statement and you're good to go.
mark hengstebeck
1,119 PointsHi William, That's it! Thanks, Mark