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 trialHarold Davis
Courses Plus Student 14,604 PointsFunctions with switch statement... I'm having trouble with my code I'm trying to return lat and lon but its not working
func getTowerCoordinates(amousLandmark: String) ->(Double, Double) {
switch amousLandmark { 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, long: 151.2140) default: 0 , 0
}
return (lat,lon) }
// Enter your code below
func getTowerCoordinates(location: String) ->(Double, Double) {
switch amousLandmark {
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: 0 , 0
}
return (lat,lon)
}
1 Answer
Keli'i Martin
8,227 PointsFirst off, you are trying to switch off a variable that isn't defined anywhere. amousLandmark
doesn't exist anywhere in the scope of your function. You should be switching off the location
parameter.
Second, in your switch statement, for each case you're using lat
and lon
, but those are variables that are not defined. Since the return tuple is unnamed, you don't need to set the values of lat and lon to anything before returning. You could simply return the tuple of coordinates right from each case. For example:
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)
}
Hope this helps!
Keli'i Martin
8,227 PointsI guess leaving the lat:
and lon:
on those values works also, but definitely changing amousLandmark
to location
is needed.
Harold Davis
Courses Plus Student 14,604 PointsHey thanks a ton this helped out a lot a guess i had kind of a syntax error i need to pay attention to details... I was way to sure of myself thanks Keli
Harold Davis
Courses Plus Student 14,604 Pointsthat and the i did not realize i should be using a return for each case statement but it makes sense for this particular situation
Keli'i Martin
8,227 PointsNot a problem! There are certainly a number of different ways to accomplish the same thing. Using returns in each case statement is just one approach. You were on the right track, so keep it up!
Mazen Halawi
7,806 PointsMazen Halawi
7,806 PointsAdd the return on the case statement
case "Eiffel Tower": return (lat: 48.8582, lon: 2.2945)
Do that for the rest. Im typing on an ipad so i cant type everything. ;)