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 trial

iOS Swift 2.0 Collections and Control Flow Control Flow With Conditional Statements Working with Switch Statements

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

How 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.

switch.swift
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
STAFF
Pasan Premaratne
Treehouse Teacher

Richard Lu

Actually 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
Richard Lu
20,185 Points

Oh cool, thanks for pointing that out Pasan Premaratne. I'm learning something new everyday. Cheers :)

Richard Lu
Richard Lu
20,185 Points

Hey 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)
  }
}

How 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
Richard Lu
20,185 Points

Hey 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
Pasan Premaratne
Treehouse Teacher

Richard Lu

Actually 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
Shandas Duchintav
8,222 Points

Gotta remove my question. Awesome.