Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Functions in Swift Adding Power to Functions Function Parameters

Nigel Matheson
PLUS
Nigel Matheson
Courses Plus Student 1,166 Points

stuck on this question regarding functions

i know i'm close but just not close enough regarding functions question

functions.swift
// Enter your code below
func getRemainder (a: value, b:divisor) return: Int

2 Answers

tromben98
tromben98
13,273 Points

Hi Nigel!

I think that you should repeat the previous videos in order to learn about return types and parameter names

Best regards, Jonas

// Enter your code below
func getRemainder (value a: Int, divisor b: Int) -> Int {
return a % b
}
Habib Miranda
Habib Miranda
7,320 Points

You are creating a return type the same way you are creating a function parameter. The Parameter of the function (what's inside the parenthesis) require a name. For example:

function nameOfFunc(nameOfParam1: Int, nameOfParam2: Int) {
}

Now in order to add a return type to the function, you simply add the return type without naming it. It looks like you are trying to assign a name to your return. You don't need to name it with the name: Type syntax. You simply need to declare what type it is with the -> Type syntax. See the example:

function nameOfFunc(nameOfParam1: Int, nameOfParam2: Int) -> Int {
     return nameOfParam1 % nameOfParam2
}