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 trialjc laurent
6,351 Pointsworking in playground but not here?
why is it bugging?
// Enter your code below
func temperatureInFahrenheit(temperature: Double) -> Double {
let fahrenheitValue = temperature * 9 / 5 + 32
return fahrenheitValue
}
let fahrenheitTemp = temperatureInFahrenheit(temperature: 24)
6 Answers
jc laurent
6,351 PointsWaow, things are so clear when you explain them. thks
Kevin Elliott
15,653 PointsYour code is failing because you are specifying the parameter name temperature when calling temperatureInFahrenheit. Even though you have an internal parameter name defined in your function, you have not specified an external parameter name. Only when you have defined an external parameter name will you be able to call the function with the parameter names explicitly.
Example with external parameter name:
func exampleFunction(thing thing: String) -> String {
return thing
}
exampleFunction(thing: "Hello")
Example with no external parameter name:
func exampleFunction(thing: String) -> String {
return thing
}
exampleFunction("Hello")
Remove the explicit call to the parameter name in your function call and your task will pass.
jc laurent
6,351 PointsHi Kev, Doesn't change nothing if I'm adding an external but still having this error: swift_lint.swift:8:45: error: extraneous argument label 'temperature:' in call let fahrenheitTemp = temperatureInFahrenheit(temperature: 24)
Kevin Elliott
15,653 PointsHey JC, you just need to remove it, and do the second example I showed.
jc laurent
6,351 PointsHi Kev, that's not what I've done?
Kevin Elliott
15,653 PointsNope! But that's ok. Look at my two examples again, closely. The second one is the one you want.
jc laurent
6,351 Pointswhere is so different?
Kevin Elliott
15,653 PointsThe call of the function does not have any named parameters. Just the value.
jc laurent
6,351 Pointstemperature in the call function is not a parameter?
jc laurent
6,351 PointsHi Bud I thks you anyway for your kind of help but it would have been so simple saying (because I love to understand) that in playground you call the function with the parameter but not in the challenge, instead of playing mystery clue!
Kevin Elliott
15,653 PointsAhh, was not trying to be mysterious. My point is that if you define an external parameter name in your function definition, then you need to provide it when you actually call the function. And when you do not have an external parameter named, then you can not provide it when you call the function. My two examples illustrate that.
If this is not behaving properly in Playground, that seems like something is wrong with the playground you have.
Kevin Elliott
15,653 PointsIt has nothing to do with being in your project or being in the Playground. It has everything to do with how you define your function.