iOS Functions in Swift Functions in Swift Recap: Functions

Ranak Bansal
Ranak Bansal
1,207 Points

Functions Code Challenge Help

So I ended up finishing and completing the code challenge correctly, but I'm not sure why my code works.

Questions:

Why don't we have two separate variables for temperature in Celsius and temperature in Fahrenheit?

How can temperature be equal to temperature times 9, divided by 5, plus 32?

Lastly, what does 'return temperature' do for us in this case?

BTW, this is the completed and correct code for the challenge

Thanks

functions.swift
// Enter your code below
func temperatureInFahrenheit(temperature: Double) -> Double  {

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

}

let fahrenheitTemp = temperatureInFahrenheit(temperature:24)

1 Answer

Jeff McDivitt
Jeff McDivitt
23,964 Points

Hi Ranak -

There is no need for two separate values as the input of the function variable temperature is the temperature in celsius For the second question you are letting a constant temperature equal the inout parameter of temperature times 9 divided by 5 plus 32 Finally you are returning that variable