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 trialRuth Yoel
986 PointsReturning a tuple
I wrote the code on Xcode and produced a tuple, but when I copied it to the editor window, I received a bummer informing me that my function needs to produce a tuple. Can you help showing me what I did wrong?
Thanks a lot!
Ruth
// Enter your code below
func coordinates(for location: String) -> (lat: Double, lon: Double) {
var lat: Double = (0.0)
var lon: Double = (0.0)
if location == "Eiffel Tower"{
lat = (48.8582)
lon = (2.2945)
} else if location == "Great Pyramid"{
lat = (29.9792)
lon = (31.1344)
} else if location == "Sydney Opera House"{
lat = (33.8587)
lon = (151.2140)
} else {
lat = (0.0)
lon = (0.0)
}
return (lat, lon)
}
5 Answers
Michael Ayoub
7,689 PointsThe directions say you do not have to name the return values so func coordinates(for location: String) -> (Double, Double) you must remove lat and lon from the return values
Ben Shockley
6,094 PointsIn the header of your function, where you declared the return type, you don't need the titles inside the tuple, (the lat: and the lon: part). When I removed those, it passed without and issue.
Probably, for whatever test they are using to check them answer, the titles are throwing it off in the return.
So your function header should look like this.
func coordinates(for location: String) -> (Double, Double)
Hope that helps.
-- Ben
Ruth Yoel
986 PointsThanks a lot!
mazvydasb
7,349 PointsEssentially you got it almost correct. However try using a switch statement and make sure you are returning touple as return types specifies "(lat: Double, lon: Double)".
This esentially what the editor is looking for.
func coordinates(for location: String) -> (lat: Double, lon: Double) {
var lat: Double = 0.0, lon: Double = 0.0
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: return (0,0)
}
return (lat, lon)
}
Ben Shockley
6,094 PointsI just tried to run your code and it didn't work either, because the tuple has the titles in it.
Ruth Yoel
986 PointsThanks a lot!
Ruth Yoel
986 PointsThanks a lot!
Ruth Yoel
986 PointsThat's very logical. It works. Thanks a lot!
Ruth Yoel
986 PointsIt worked! Thank you very much!
Tomas Salas
Front End Web Development Techdegree Graduate 37,934 Pointsthe code challenge tells you not to put global names to the return type, jus try to get the return tuple without global or local names.
Ruth Yoel
986 PointsRuth Yoel
986 PointsThanks a lot!