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 trialKjartan Ottosson
809 PointsI have no clue why this isnΒ΄t working, can you help me?
Hi, kinda lost at the moment. Had a look at some community answers but still no luck. Can you help?
Regards, Kjartan
// Enter your code below
func coordinates (for location: String) -> (Double,Double) {
var lat: Double = 0,0 lon: double = 0,0
switch location {
case "Eiffel Tower":
return (lat: 48.8582, lon: 2.2945)
case "Great Pyramid":
return (lat = 29.9792, lon = 31.1344)
case "Sydney Opera House":
return (lat = 33.8587, lon = 151.2140)
default:
return (lat = 0.0, lon = 0.0)
}
return(lat,lon)
}
coordinates("Eiffel Tower")
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Kjartan,
You are on the right track, but there are a few things going wrong here.
- First, the challenge didn't ask for you to declare any variables (You have
lat
andlon
. Also, with this line, the syntax is incorrect. If you were to declare those variables, they would need to be declared separately. You cannot declare two different variables with only onevar
keyword. (Maybe have a quick review on variables.) - Second, also has to do with the
lat
andlon
variables you are using. The challenge asks that you return the values, but that you don't have to name the return values. Inside of yourswitch statement
you are using names. - Third, you have to return the values based on which
case
matches inside the switch statement (which you are doing), so you can't return anything outside of theswitch
, as there would be nothing to return. - Lastly, you are calling the function. The challenge did not ask for a function call, so although this is correct syntax, it will cause the challenge to fail. Challenges are very picky and extremely specific. If you add something that wasn't asked for, it will more often than not throw a Bummer.
I don't normally give the corrected code outright, but I have provided it below for you to review and compare. Have a look, and I hope it all makes sense for you.
func coordinates (for 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, 0.0)
}
}
Keep Coding! :)
Kjartan Ottosson
809 PointsThank you so much Jason!
Kjartan Ottosson
809 PointsThank you :)
Ulan Assanoff
9,922 PointsUlan Assanoff
9,922 PointsJust try in this way