Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,627 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