iOS Functions in Swift Functions in Swift Recap: Functions

Lana Wong
Lana Wong
3,968 Points

Functions match the directions correctly. What am I doing wrong?

The complier said:

Bummer! Make sure the operation you're carrying out in the body of the function matches the directions and correctly converts a Celcius temperature to Fahrenheit

My code did not work. What is wrong?

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

let celeciusTemperature = temperature * 9/5 + 32

return temperature
}

1 Answer

andren
andren
28,390 Points

You are returning the wrong thing, the temperature variable contains the temperature that was passed in to the function, you want to return the converted temperature, which you have stored in the celeciusTemperature constant.

Though it's also worth noting that you have somewhat misnamed that constant, your function takes in a temperature in Celsius and converts it to Fahrenheit. The constant you have named celeciusTemperature is the constant that holds the temperature after it has been converted to Fahrenheit, so logically it should be called fahrenheitTemperature.

Like this:

func temperatureInFahrenheit(temperature: Double) -> Double {

let fahrenheitTemperature = temperature * 9/5 + 32

return fahrenheitTemperature
}

That code will allow you to pass the second task.