Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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