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 trialRodney Gothe
369 PointsWhat would be the correct syntax here please? switch world { case "BEL", "Brussels": print("yes") }
switch world { case "BEL", "Brussels": print("yes")
2 Answers
Greg Kaleka
39,021 PointsHi Rodney,
For this challenge, you're already looping through the members of the world
dictionary. You want to switch on the key
local variable inside the loop, and append the value
to the pertinent array. Start like this:
for (key, value) in world {
switch key {
case "BEL", "LIE", "BGR":
europeanCapitals.append(value)
// rest of switch statement here
}
}
Corey F
Courses Plus Student 6,450 PointsYour syntax is wrong.
A. we are switching on the key. switch key {
B. If we are switching on the key. That means "Brussels" has no place in your code as it is a value.
"BEL"
is the only thing you need
C. print("yes") doesn't belong either... the goal of the challenge is to append the value to the appropriate array. So for the case with brussels
for (key, value) in world {
switch key {
case "BEL" : europeanCapitals.append(value)
default: print("Not Applicable")
}
}
This would be your syntax... of course you need to apply the same logic to the rest of the key and values.