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 Swift Functions and Optionals Optionals Review: Functions

I'm stuck on this challenge and can't seem to get past the basic setting up of the code.

Thanks

divisible.swift
func isDivisible(#dividend: Int, #divisor: Int) -> Bool {
    if dividend % divisor == 0 {
        return true
    } else {
        return false
    }
}
func isNotDivisble(#divedend: Int, #divisor: Int) -> Bool {
    if divisor % divedend == 0 {
        return true 
    } else {
        return false
    }
}

1 Answer

Taking a brief look without context, it seems as if you forgot to check what the modulo operator returns.

% will basically give you the remainder if you took the number before and divided it by the number after the operator.

For the isNotDivisible function, I think you may want to check if the operator does NOT return 0. This would mean that a remainder would exist.

So basically the code for the isNotDivisible function should be about the same as the function before it, except you should change one line illustrated below.

What you have:

if divisor % divedend == 0

What it should be:

if dividend % divisor != 0

Also, in the code above, I changed your spelling of dividend. Be sure to update the parameter name as well.

Here is a good reference straight from Apple. Look for "Remainder Operator".

I hope this helps.

It worked, thank you!