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 Collections and Control Flow Control Flow With Conditional Statements Working With Switch Statements

I have no idea to comlete this task!

I don't know how to go about completing this task, can someone please help me!

operators.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
    switch world {
      case "BEL" "Brussels": europeanCapitals.append(value)
      case "LIE" "Vaduz": europeanCapitals.append(value)
      case "BGR" "Sofia": europeanCapitals.append(value)
      case "Brussels": europeanCapitals.append(value)
    }
    // End code
}

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

you're close. the variable you need to switch on is key, not world. depending on what key is, you append value to the various lists. then that means each case is only for the key, not key value. so in the case of a certain key, do whatever with the corresponding value. here you append the value to a given list. then you just need a case for each key and a default and whatever else the challenge asks for.