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 Functions Function Parameters Returning Complex Values

William Lee
William Lee
1,316 Points

Not sure how to finish this off.

I know my code is faulty. I just can't pinpoint exactly where and how to fix it. Any help is much appreciated :D

functions.swift
// Enter your code below
func getTowerCoordinates(location: String) -> (Double, Double) {
switch location {
  case "EIffel Tower": print(48.8582, 2.2945)
  case "Great Pyramid": print(29.9792, 31.1344)
  case "Sydney Opera House": print(33.8587, 151.2140)
  default: (0,0)
  }
  return bleh idk help me please. 
}

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi. There're quite a few issues with the code.

  • "EIffel Tower" is a misspelled, only the first letter of Eiffel needs to be capitalized.
  • The use of print() statements are incorrect here.
  • Right before the switch statement, you need to declare a variable, type (Double, Double), and assign value to the variable at each case in the switch statement, on top of that, this variable also serves as the return value of the function.
  • last but not least, it's essential to properly indent your code block for better readability. Clean code matters.
// Enter your code below
func getTowerCoordinates(location: String) -> (Double, Double) {
  var coordinate: (Double, Double)
  switch location {
    case "Eiffel Tower": coordinate = (48.8582 , 2.2945)
    case "Great Pyramid": coordinate = (29.9792 , 31.1344)
    case "Sydney Opera House": coordinate = (33.8587 , 151.2140)
    default: coordinate = (0,0)
  }
  return coordinate
}

Hope it helps. Please refer to this lecture for refreshing on the materials

William Lee
William Lee
1,316 Points

You're right. Going over the lectures really showed where the gaps in my knowledge! Thank you William.