iOS Functions in Swift Functions in Swift Recap: Functions

Randell Purington
Randell Purington
9,992 Points

I need some assistance please

This has been driving me crazy. I have followed other answers given on this same question but it isn't working. I can get it to work in Xcode but not on the quiz, What am I doing wrong?

Challenge Task 3 of 3

Sweet, we have a function! In this task, all you have to do is call the function and pass in a value of 24.0 degrees. Assign the result of the function to a constant named fahrenheitTemp.

functions.swift
// Enter your code below

func temperatureInFahrenheit(temperature: Double) -> Double {
    let fahreheitTemp = ((temperature * 9) / 5) + 32
    return (farenheitTemp)
    }
let fahrenheitTemp = (temerature:24.0)

1 Answer

Jennifer Nordell
MOD
Jennifer Nordell
Treehouse Moderator

Hi there, Randell! I'm not sure exactly why this is running in Xcode unless the code there differs somewhat. Mainly, you have some spelling errors. Inside your function, you declare a variable named fahreheitTemp but are trying to return the value of farenheitTemp note that these names differ from each other and neither is correctly spelled. It should be fahrenheitTemp. That being said, you don't need the variable at all, rather you could return the result directly:

return temperature * 9 / 5 + 32

Secondly, you spelled the label of the parameter as temperature but have spelled the label as temerature.

Also, you never call the function. I would expect to see the call to the function as:

let fahrenheitTemp = temperatureInFahrenheit(temperature:24.0)

Hope this helps! :sparkles:

Randell Purington
Randell Purington
9,992 Points

Thank you. I am not sure why it ran in Xcode either. Thank you for the help. It passed.