iOS Functions in Swift Functions in Swift Recap: Functions

mark hengstebeck
mark hengstebeck
1,119 Points

Recap: functions task 2 of 3. Will someone provide me with a hint as to how to continue beyond task 1 of 3?

// Enter your code below func temperatureInFahrenheit(temperature: Double) -> Double { let temperatureInFahrenheit = temperature return(temperatureInFahrenheit)

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

3 Answers

Ryan Lee
Ryan Lee
13,806 Points

You need to assign the result of the expression they gave you in the directions.

"To convert from Celcius to Fahrenheit - multiply the value by 9, divide the resulting value by 5 and then add 32."

note: when they say multiply the value, they really mean temperature in this case because that is the parameter in our function's signature

Instead of just passing the argument temperature straight into your constant, do the math above and assign it to the constant, this way, your temperatureInFahrenheit constant holds the correct temperature in fahrenheit, converted from celcius

Also on your return statement, get rid of the parenthese around your constant's name, you want to only return the temperatureInFahrenheit, not a tuple.

mark hengstebeck
mark hengstebeck
1,119 Points

Hi Ryan, That's it! Thank You, Mark

mark hengstebeck
mark hengstebeck
1,119 Points

Am I moving in the correct direction now for step 2 of 3? // Enter your code below func temperatureInFahrenheit(temperature: Double) -> Double { let temperatureInFahrenheit = temperature * 9 / 5 + 32 return temperatureInFahrenheit }