iOS Functions in Swift Functions in Swift Recap: Functions

Recap: Functions

Hi guys, I have been really stuck with this question and still do not understand how I should write the code for converting fahrenheit to celsius. Can someone help me? Thanks.

functions.swift
func temperatureInFahrenheit(temperature: Double) -> Double {
temperatureInFahrenheit

}

1 Answer

Scott Lougheed
Scott Lougheed
14,119 Points

Hi GamingWithHan, So you've got the function declared, you've got to fill it in with the actual tasks you want it to perform. I don't want to just give you the answer but here's some guidance

Have you been able to pass the first part of the challenge? (remember, to pass the first part of the challenge you have to add

return temperature

as a placeholder which you will be removing in the next step.

Once you pass step 1, in step two, you have to fill in the actual arithmetic to do the conversion. The instructions tell you the math needed (remember the order of operations!):

Take the temperature in Celsius (passed into the function as the 'temperature' variable), multiplied by 9, the product of which is divided by 5, to which you add 32. The math (with parentheses to force the correct order of operations) should look roughly this:

((temperature*9)/5)+43

(where "temperature" is the variable temperature passed into the function)

This would have to be assigned to a constant that you return in the next line of code.

Does that help?

Thanks Scott so much! Also, I was able to pass the first task.

Scott Lougheed
Scott Lougheed
14,119 Points

Great I'm glad you were able to get things sorted out. If you have any other trouble I'm sure the community would be happy to help!