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

Make sure your function accepts two parameters, with the correct external and local names

Not working please some help

functions.swift
// Enter your code below 
func getRemainder(a value: Int, b divisor: Int) -> Int {
let operation = a % b
return operation
}

//Have tried // Enter your code below func getRemainder(a value: 10 , b divisor: 5) -> 2 { let operation = 10 % 5 return operation } //Then this // Enter your code below func getRemainder(a value: Int, b divisor: Int) -> Int{ let operation = value % divisor return operation } //Before this // Enter your code below func getRemainder(a value: Int, b divisor: Int) -> Int{ let operation = a % b return operation }

2 Answers

James Vlok
James Vlok
17,059 Points

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

a and b are the external names for the variable. value and divisor are the names for the variable in the function. eg.. when you call the function you would do the following:

getRemainder(a: 5, b: 10)

hence a and b here are used externally from the function

In the function: let operation = value % divisor

value and divisor are used.

So in the function you will use value instead of a and divisor instead of b.

value and divisor are just names for the same variable to make the code more readable.

// not working func getRemainder(a value: Int, b divisor: Int) -> Int { let operation = value % divisor return operation }

James Vlok
James Vlok
17,059 Points

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

This should work. the question states that the external variable names need to be value and divisor. In the function definition just swap value and a , divisor and b

Sorry didn't see that it was apart of a code challenge.

All the best