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

Chris Miller
Chris Miller
2,186 Points

Capitals Compound Statement Challenge STUCK

error: Control Flow.xcplaygroundpage:195:16: error: expected expression case: "IND", "VNM": asianCapitals.append(value)

When running what I have in the playground this is what I get.

I seem to continue to get stuck on the concept of reassigning content into arrays. I get reading them for the most part but in all the video lessons in this section the instructor only ever prints out the info. I "think" based on earlier lessons this is the correct format but obviously I am again missing some painfully obvious thing. Any help would be appreciated. Thanks!

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

    // End code
}

3 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

You mostly have this one correct, you just have some colons in the wrong place

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 "IND", "VNM": asianCapitals.append(value)
    default: otherCapitals.append(value)

    // End code
}
}
Chris Miller
Chris Miller
2,186 Points

Thank you... (I feel stupid again) :). Looked back through my earlier samples and could swear I saw : after each case statement. Thank you.

Jeff McDivitt
Jeff McDivitt
23,970 Points

It happens to all of us! Don't sweat it :)