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 Function Scope

TERRELL TINSLEY
TERRELL TINSLEY
2,964 Points

Why won't this work?

Can some one explain to me why this code wouldn't work during the quiz but it works in my playground? And is the other way better than the way I did it? If so can you explain why.

func getTowerCoordinates(location: String) -> (Double, Double) {

    var coordinates: (Double, Double)

    switch location {
    case "Eiffel Tower": coordinates = (48.8582, 2.2945)
    case "Great Pyramid": coordinates = (29.9792,31.1344)
    case "Sydney Opera House": coordinates = (33.8587, 151.2140)
    default: coordinates = (0, 0)
    }

    return coordinates
}

getTowerCoordinates("Eiffel Tower")
Evgeny Nagimov
Evgeny Nagimov
4,075 Points

You did everything correct. Just the last line of code shouldn't be there. Delete it and that's it!

func getTowerCoordinates(location: String) -> (Double, Double) {

var coordinates: (Double, Double)

switch location {
case "Eiffel Tower": coordinates = (48.8582, 2.2945)
case "Great Pyramid": coordinates = (29.9792,31.1344)
case "Sydney Opera House": coordinates = (33.8587, 151.2140)
default: coordinates = (0, 0)
}
return coordinates

}

5 Answers

Marina Alenskaja
Marina Alenskaja
9,320 Points

The challenge says you have to be able to pass in a landmark and have the coordinates be returned to you - which is why your answer didn't pass, since it only returns all the coordinates for all the landmarks instead. Hope that makes sense :-)

Marina Alenskaja
Marina Alenskaja
9,320 Points

Hi! Here is my answer - maybe that will help you see where the error is?

func getTowerCoordinates(location: String) -> (Double, Double) {
    switch location {
    case "Eiffel Tower": return (48.8582, 2.2945)
    case "Great Pyramid": return (29.9792, 31.1344)
    case "Sydney Opera House": return (33.8587, 151.2140)
    default: return (0,0)
    }
}

getTowerCoordinates("Eiffel Tower")
Adam Beck
Adam Beck
9,345 Points

Thanks for posting this, it works! I was thrown off because I have never seen the instructor use the 'return type' like that! Arg! Learned something new..

Marina Alenskaja
Marina Alenskaja
9,320 Points

oh and the -&gt is of course my arrow ->

TERRELL TINSLEY
TERRELL TINSLEY
2,964 Points

I figured out the "correct" answer. I just didn't understand why the way I did it wasn't being accepted, but I get the same result. Thanks though!

TERRELL TINSLEY
TERRELL TINSLEY
2,964 Points

Ahhh yes, that does make sense. It's always the small things that trip you up when programming. Thanks again.