Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Functions in Swift Adding Power to Functions Function Parameters

Hello Treehouse friends. Can't see what I'm doing wrong, can you help, please.

I've spent lots of time trying to solve this one. Please help.

Thank you,

John

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

let division = a % b

}

getRemainer(value, divisor)

4 Answers

Hi John,

The solution I provided does work.

The challenge has two stages:

func getRemainder(value a: Int, divisor b: Int) -> Int {
    return a % b
}

The second stage does require the function to be called:

let result = getRemainder(value: 10, divisor: 3)

Also, the solution you provided does work, but remember to write Int with a capital I not int.

I hope this helps!

Mitch

Hi John!

There are simply a few small steps that you have missed out when creating this function.

You have correctly labelled the parameters but you must remember to declare what the parameter is returning using '->'.

func getRemainder(value a: Int, divisor b: Int) -> Int 

Secondly, the challenge asks you to return an operation. Although you have declared this operation correctly, you have not returned it.

return a % b

The challenge then asks you to call the function and assign it to a constant named result.

let result = getRemainder(value: 10, divisor: 3)

The overall solution should look like this:

func getRemainder(value a: Int, divisor b: Int) -> Int {
    return a % b
}

let result = getRemainder(value: 10, divisor: 3)

I would strongly recommend fully understanding the solution here, and then come back to it in a day or two to reinforce your knowledge through retrieval.

All the best!!

Mitch

Hi Mitch,

Thanks very much, I read through the fact they wanted a return. I tried the solution provided, but it was not accepted.

The solution provided "calls" the function, but that is not a requirement?

This is what I have, and it is still not accepted.

Any other ideas?

func getRemainder(value a: int, divisor b: int) -> int { return a % b
}

This should work, but it does not. Help please.

func getRemainder(value a : Int, divisor b: Int) -> Int { return a & b }

Awesome Mitch!!!

Mine wasn't working because I was using int 'lower case "i" ' to designate an integer. When I compared it against yours, I see that yours was: Int with a capital 'I' not lower case, as I had mistaken.

I thank you very much, and have a great day!!!

Glad we figured it out!

Have a great day yourself and all the best!

Mitch