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 Functions in Swift Adding Power to Functions Returning Complex Values

Tanner Shelton
seal-mask
.a{fill-rule:evenodd;}techdegree
Tanner Shelton
iOS Development Techdegree Student 1,136 Points

I'm not exactly sure what this is asking or where I'm going wrong.

I'm not exactly sure where "for" fits in here.

functions.swift
// Enter your code below
func coordinates(for:String) -> (Double,Double) {
   var location = (0.0, 0.0)
    if for == "Eiffel Tower" {
        location = (48.8582, 2.2945)
    } else if for == "Great Pyramid" {
        location = (29.9792, 31.1344)
    } else if for == "Sydney Opera House" {
        location = (33.8587, 151.2140)
    } else {
        location = (0,0)
    }
    return location
}



coordinates(for: "Eiffel Tower")
Rogier Nitschelm
seal-mask
.a{fill-rule:evenodd;}techdegree
Rogier Nitschelm
iOS Development Techdegree Student 5,461 Points

I am not entirely sure - because I do not know the exact question (I tried looking it up based on the signature of the function you wrote). But I will give it a shot:

In swift it is possible to declare an external function parameter. With this external parameter, you can call the function instead of the internal parameter. Which is nice as it allows for even more English-like function-calling.

func coordinates(for location: String) -> (Double, Double) {
    if location == "Eiffel Tower" {
      return (12.34, 45.56)
   } ...
}

var coordinate = coordinates(for: "Eiffel Tower")  // instead of coordinates(location: "Eiffel Tower")
print(coordinate) // 12.34, 45.56

1 Answer

Emin Grbo
Emin Grbo
13,092 Points

You just mixed some stuff up.

Internal and external coordinates are the arguments you pass TO the function, so they only wanted you to have "for location" when creating it.

func coordinates(for location: String) -> (Double, Double){

FOR is external, meaning you will use it only when you call the function later on, not inside of it. (therefore the name :))

coordinates(for: "Eiffel Tower") |

And location is used within a function, like you did, so the only issue is to remove the "for" you added in the "if else" statements :)

func coordinates(for location: String) -> (Double, Double){

  if location == "Eiffel Tower" {
  return (48.8582, 2.2945) 
  } else if location == "Great Pyramid" {
  return (29.9792, 31.1344) 
  } else if location == "Sydney Opera House"{
  return (33.8587, 151.2140) 
  } else {
  return (0,0)  
  }

}