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 trialSam Belcher
3,719 PointsReturning Complex Values
I'm confused, not sure how to fix my mistake :/
// Enter your code below
func coordinates(for location: String) -> (Double, Double) {
var place: Double = []
switch location {
case "Eiffel Tower": place = [48.8582, 2.2945]
case "Great Pyramid": place = [29.9792, 31.1344]
case "Sydney Opera House": place = [33.8587, 151.2140]
default: place = [0.0, 0.0]
}
return(place)
}
1 Answer
JLN CRML
30,362 PointsHi, you try to assign an empty array to a variable of type Double, which is not possible. You also might rather want to use Tuples here, since they always have two values, perfectly fitting for coordinates.
I am showing you below two methods of solving this without changing the signature, either with Tuples, which I would recommend, or Arrays.
func coordinates(for location: String) -> (Double, Double) {
var place: (Double, Double)
switch location {
case "Eiffel Tower": place = (48.8582, 2.2945)
case "Great Pyramid": place = (29.9792, 31.1344)
case "Sydney Opera House": place = (33.8587, 151.2140)
default: place = (0.0, 0.0)
}
return(place)
}
func coordinates(for location: String) -> (Double, Double) {
var place: [Double] = []
switch location {
case "Eiffel Tower": place = [48.8582, 2.2945]
case "Great Pyramid": place = [29.9792, 31.1344]
case "Sydney Opera House": place = [33.8587, 151.2140]
default: place = [0.0, 0.0]
}
return(place[0], place[1])
}