iOS Functions in Swift Adding Power to Functions Function Parameters

Nigel Matheson
PRO
Nigel Matheson
Pro Student 1,166 Points

A little confused

I think I'm getting muddled up, please help

functions.swift
// Enter your code below
func getRemainder (value a: int, divisor b: int)-->return{ remainder operator}

3 Answers

Sarah Hurtgen
Sarah Hurtgen
Treehouse Project Reviewer

Hi!

You've done a great job setting the parameters (although you will want to make sure and capitalize the "i" in Int), it just looks like you're getting a little sidetracked after that. The " -> " in your function can be read as "return", so intead of typing return again after your arrow, you can simply specify the value you want to return. The challenge wants you to give the return type a value of Int.

For example, if you were creating a function named giveExample, with a return type of String, it would look something like this:

func giveExample() -> String {
}

This lets you know that whatever the body of the function returns, will be of type String.

Once you have that set up, you will need to specify the body of your function to return the needed Int. For my example I showed that I would return a String, so that requirement would be met by simply putting in the body:

func giveExample() -> String {
     return "This string will be returned when this function is called!"
}

For this project, you've been asked to calculate the remainder by "carrying out the operation a modulo b". If you need a refresher on the modulo operator (also known as the remainder operator) this Treehouse video should help you out.

I hope that helps!

Jeff McDivitt
Jeff McDivitt
23,964 Points

Your function is almost correct but you need to return value % divisor

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

    return a % b

}