iOS Functions in Swift Functions in Swift Recap: Functions

Hello, I have a problem with Challenge Task 3 of the Swift module on Functions.

I was able to create a function but had problem with the last step: calling a function and assigning its value to a constant. The compiler errors says that I was wrong in specifying the argument, but I can't see why. Please find below the code:

---Swift func temperatureInFahrenheit(temperature: Double) -> Double {

let temperatureInFahrenheit = temperature * 9 / 5 + 32 return temperatureInFahrenheit }

let fahrenheitTemp = temperatureInFahrenheit(24.0)

---Swift

Many thanks!

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

 let temperatureInFahrenheit =  temperature * 9 / 5 + 32
    return temperatureInFahrenheit
}

let fahrenheitTemp = temperatureInFahrenheit(24.0)

1 Answer

David Lacedonia
David Lacedonia
13,626 Points

This is how I did it

func temperatureInFahrenheit(temperature: Double) -> Double {
  return temperature * 9 / 5 + 32
}

let fahrenheitTemp = temperatureInFahrenheit(temperature: 24.0)

You should specify the parameter name, when you call the function And is not necessary to create the variable 'temperatureInFahrenheit' inside the function 'temperatureInFahrenheit', just return the result