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