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

Nigel Matheson
PLUS
Nigel Matheson
Courses Plus 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
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
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,970 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

}