iOS Functions in Swift Functions in Swift Recap: Functions

Tanner Shelton
Tanner Shelton
iOS Development Techdegree Student 1,136 Points

Why is fahrenheitTemp not returning my results?

func temperatureInFahrenheit(temperature: Double) -> Double {

    let fahrenheitTemp = (temperature * 9)/5 + 32
    return fahrenheitTemp

}

   let temperature = 24.0

Moderator edit: added Markdown so the code can be read in the Community. Please, when posting code, refer to the Markdown Cheatsheet located above the Post button

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 142,203 Points

Hi Tanner,

It looks like you are trying to assign a value to the parameter instead of calling the function with a parameter passed in, as the instructions are stating. Remember when calling a function it is the function name with the parameter(s) passed into the parenthesis => functionName(parameter)

Have a look over the part of the code where you should be calling the function. The rest looks good! :thumbsup:

Keep Coding! :) :dizzy:

Tanner Shelton
Tanner Shelton
iOS Development Techdegree Student 1,136 Points

Can you elaborate? I'm doing this the same way it was done in the demonstration videos.

Jason Anders
Jason Anders
Treehouse Moderator 142,203 Points

Your last line: let temperature = 24.0 is trying to assign a hard-coded value to the variable, but the instructions specifically state to store the "return of the function call to the variable".
So, you need to call the function with the value of 24.0 passed in, and then store that into the variable named fahrenheitTemp not temperature:

let fahrenheitTemp = temperatureInFahrenheit(temperature: 24.0)
Tanner Shelton
Tanner Shelton
iOS Development Techdegree Student 1,136 Points

Thanks for the help Jason. Figured it out a little bit ago. Much appreciated!