iOS Functions in Swift Functions in Swift Recap: Functions

I need help setting this function up correctly

Can someone please explain what i'm missing or doing wrong and how to set it up

functions.swift
// Enter your code below
func temperatureInFahrenheit(temperature: Double, Celcius: Double) -> Double {
  let Celcius = temperatureInFahrenheit * 9 / 5 + 32

  return temperatureInFahrenheit
   }

These were the instructions: Let's add some code to the body of the function. Get rid of the existing return statement that's in there and in this task we're going to write out code to take a Celcius temperature value passed in and convert it to Fahrenheit.

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

Once you have the Fahrenheit value, return it from the function.

2 Answers

Rogier Nitschelm
Rogier Nitschelm
iOS Development Techdegree Student 5,460 Points

Some tips:

  • your function should only have 1 parameter (as you can calculate fahrenheit based on the temperature in celsius);
  • remember to calculate the temperature based on the argument that is passed in (as currently you are making a calculation based on the function name, which will not get you a desired result).
  • wouldn't fahrenheit be a better variable name?
  • also remember to return the value you calculate, not the function itself. So if you store the result in a variable named fahrenheit, you can then return fahrenheit. (also, you could skip variable declaration and just return the calculation itself).
Jeff McDivitt
Jeff McDivitt
23,964 Points

Rogier did a great job of explaining what needs to be done; here is the correct code

func temperatureInFahrenheit(temperature: Double) -> Double {

  return temperature * 9 / 5 + 32

}