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

Not to sure why it won't pass. It worked fine in Xcode and Im pretty sure I followed all of the rules. help?

Please explain to me why it will not pass in Treehouse but will in Xcode

functions.swift
// Enter your code below

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

    let finalAnswer = value % divisor

    return finalAnswer

}

Hey Eddie,

So for this one it just seems like your missing the local parameter names.

// Step 1: We declared our function. The function takes two parameters a and b 
// and returns a value of type Int. Inside our function we returning a % b
func getRemainder(a: Int, b: Int)  -> Int{
    return a % b
}

// Step 2: They want us to declare local names for our parameters so that 
// when call the function later we remember what it does
func getRemainder(value a: Int, divisor b: Int) -> Int {
    // We can still use a and b for convenience 
    return a % b
}

// When you call this function in xcode it will look like this
getRemainder(value: Int, divisor: Int)

1 Answer

Jonathan Ruiz
Jonathan Ruiz
2,998 Points

Hi Eddie for this problem one thing that isn't letting you pass is the external names for the parameters. For functions with parameters the external name is what is read when you call a function. And a local name is what is used inside the body of the function, the internal name doesn't show up when the function is called. In your code above you don't have the external names the problem wanted.

func nameExample(for example: Int) {
     // in this function for is the external name that is read when you call the function. 
   // example is the local name and what you refer to inside the function
} 

For the second part of the problem make sure to create a constant they will give you a constant name. Hope this helps ! you got the idea of the function right and the task, its just important to know the logic of external and local names for parameters.