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 trial

iOS Swift 2.0 Functions Functions in Swift 2.0 Recap: Functions

working in playground but not here?

why is it bugging?

functions.swift
// Enter your code below
func temperatureInFahrenheit(temperature: Double) -> Double {
   let fahrenheitValue = temperature * 9 / 5 + 32
return fahrenheitValue
}
let fahrenheitTemp = temperatureInFahrenheit(temperature: 24)

6 Answers

Waow, things are so clear when you explain them. thks

Kevin Elliott
Kevin Elliott
15,653 Points

Your 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.

Hi 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
Kevin Elliott
15,653 Points

Hey JC, you just need to remove it, and do the second example I showed.

Hi Kev, that's not what I've done?

Kevin Elliott
Kevin Elliott
15,653 Points

Nope! But that's ok. Look at my two examples again, closely. The second one is the one you want.

where is so different?

Kevin Elliott
Kevin Elliott
15,653 Points

The call of the function does not have any named parameters. Just the value.

temperature in the call function is not a parameter?

Hi 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
Kevin Elliott
15,653 Points

Ahh, 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
Kevin Elliott
15,653 Points

It 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.