Perewillz
Perewillz

Reputation: 73

Problems using switch statements in control flow. Swift 3

Here I am trying to append the different capitals into their continental regions. can someone please tell me what I am doing wrong?

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", "LIE", "BGR" : var europeanCapitals.append(value);
    case "VNM", "IND" : var asianCapitals.append(value);
   default: var otherCapitals.append(value);
    }
    // End code
}

Upvotes: 0

Views: 44

Answers (1)

Phillip Mills
Phillip Mills

Reputation: 31026

You need to match key, not world and the var in your cases doesn't make sense.

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 key {
    case "BEL", "LIE", "BGR" : europeanCapitals.append(value);
    case "VNM", "IND" : asianCapitals.append(value);
    default: otherCapitals.append(value);
    }
    // End code
}

Upvotes: 2

Related Questions