iOS Functions in Swift Functions in Swift Recap: Functions

s t
s t
949 Points

SOS: help with IOS Swift functions test please

Hello all,

I have the following task (step 2) that I'm stuck on:

""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.""

I don't understand why the let Fahrenheit within the function should not be there... do I not have to make a variable or constant with in the function to identify the calculation I want to take place? although my question is conceptual I'm pretty sure what I have attempted to write for this function is completely wrong so a point in the right direction would be greatly appreciated.

I look forward to hearing from whomever can help,

Thanks again,

Kind regards ST

functions.swift
var celcius = 10

func temperatureInFahrenheit(temperature: Double) -> Double  {
    let fahrenheit = celcius * 9 % 5 + 32


}

2 Answers

Brandon Mahoney
Brandon Mahoney
iOS Development with Swift Techdegree Graduate 30,144 Points

3 things:

  1. You used the modulo(%) operator instead of the division(/) operator. Modulo gives you the remainder.
  2. Since we are just creating a reusable function you do not need to create a variable named celsius.
  3. Also don't forget to return the value.
// Enter your code below
func temperatureInFahrenheit(temperature: Double) -> Double {
  let fahrenheit = temperature * 9 / 5 + 32

  return fahrenheit
}

If this helped you please remember to up vote and mark it as best answer. Thanks!

s t
s t
949 Points

Once again Brandon, Thank you for your time and help!!