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

guillem Bruix
guillem Bruix
2,614 Points

I Can't complete ch. task 1 of 1 (Swift 2.0 Functions - Returning Complex Values 2) Please help

I'm doing something wrong in this challenge task:

https://teamtreehouse.com/library/swift-20-functions/function-parameters/returning-complex-values-2

My code seems to works well in my Playground, but not in the Treehouse's checker :( I can't find where is the mistake. Any help? Thanks!

functions.swift
// Enter your code below
func getTowerCoordinates(location:String) -> (lat:Double, lon:Double){

    var lat:Double
    var lon:Double

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

4 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

Your code is good, but the challenge does not specify to name the elements in the tuple, and also says to return (0,0).

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

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

Hope this helps.

Raphael Reiter
Raphael Reiter
6,820 Points

Hey Jhoan: I don't understand your default and return, you write (0,0). Aren't those integers? i wrote (0.0,0.0) and (0.0,0.0) to have two doubles, but it didnt work. when I wrote your code, I passed. Can you please explain why? thanks :)

Jhoan Arango
Jhoan Arango
14,575 Points

Hey Raphael:

You can put an whole number ( integer ) in a type double if you like. It's accepted, but you cannot do it the other way.

var double: Double = 53 // This is accepted.
var integer: Int = 0.0 // This gives an error.

Hope that answers your question.