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

Cannot assign the value returned by a function to a new constant.

Hi, this is the code I wrote:

---Swift

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

return(a % b)

}

let result = getRemainder(10, 3)

---Swift

What am I doing wrong?

Thank you

functions.swift
// Enter your code below

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

    return(a % b)
}

 let result = getRemainder(10, 3)

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Tatiana! Oh wow you are soooo close to having this correct! You set up value and divisor as your external labels. This means that you have to use them when calling the function, otherwise you'll get a compiler error. Take a look at how close you really are:

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

Hope this helps! :sparkles:

Thank you Jennifer!

andren
andren
28,558 Points

When you are stuck on challenges it can often be helpful to press the preview button and look at the error message being produced, the errors can often be more helpful than you might expect.

swift_lint.swift:13:27: error: missing argument labels 'value:divisor:' in call
 let result = getRemainder(10, 3)
                          ^
                           value:  divisor: 

The error comes from the fact that you did not assign labels to the arguments when you called your method, adding the labels that you specified when you created the method like this:

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

Will allow your code to pass the challenge.

Thank you Andren!