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

Zulfikhar Fikar
Zulfikhar Fikar
3,900 Points

what i have to do, when i wrote the code in FahrenhaitTemp, its getting error

this is the code that i have been written:

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

let fahrenheitTemp = temperatureInFahrenheit (24.0)

but ya..bummer, please help me, thanks

functions.swift
func temperatureInFahrenheit(temperature: Double) -> Double {
    let fahrenheit = (temperature * 9 / 5) + 32
    return fahrenheit
}

let fahrenheitTemp = temperatureInFahrenheit(24.0)

1 Answer

andren
andren
28,558 Points

In situations where your code does not work for mysterious reasons it can often be a good idea to look at the compiler errors that Swift generates. They are often more informative than you might expect. To see them just click the "Preview" button after an error has occurred.

For your code the compiler error generated is this:

swift_lint.swift:12:46: error: missing argument label 'temperature:' in call
let fahrenheitTemp = temperatureInFahrenheit(24.0)
                                             ^
                                             temperature: 

That error message not only point out what is wrong but practically tells you what to do to fix it. You forgot to write the label for the argument so all you have to do is add it like this:

let fahrenheitTemp = temperatureInFahrenheit(temperature: 24.0)

And then your code will work.