iOS Functions in Swift Functions in Swift Recap: Functions

Michele Livingston
Michele Livingston
iOS Development Techdegree Student 808 Points

How do you add a type double?

The question ask to make temperature of type double. What does that mean in the code.

functions.swift
// Enter your code below
func temperatureInFahherinheit (temperature: Int) {
     = 
    return temperature
}

2 Answers

andren
andren
28,391 Points

Double is a type of value, like Int and String. It is used for storing numbers with decimal values like 3,14 or 532,2532, etc. The Int value type is only used to store whole number without decimals like 5 or 6324, etc.

So "in code" it means that you have to declare the temperature variable as type Double not Int, you also need to declare the return type as Double. It also seems you have a typo in the name of your function that you'll need to fix before you can continue to the next task.

andren
andren
28,391 Points

In the same way you declare it for other types, like this:

func exampleFunction (value: Double) -> Double {
}

The "-> Double" part of that example function is specifically where I define the return type, did you accidentally skip the video that preceded this challenge? The Return Types video introduces the concept of return types, and shows off how they work.

Daniel Walker
Daniel Walker
2,031 Points

so you have :

// Enter your code below
func temperatureInFahherinheit (temperature: Int) {
     = 
    return temperature
}

you should make it more like this if your looking for an answer with a decimal point.

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