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

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