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

This is confusing

So in the video before this it's telling me that in the next challenge I'm going to make a function called "isDivisible" where it tells if something is divisible or not, returns a boolean, then prints "Divisible" or "Not Divisible". Now when I get here it's telling me that I have to make a function called "isNotDivisible" that does the opposite so I first followed the challenge instructions and deleted the isDivisible thing, which didn't work. Then I tried doing it with the isDivisible function. I didn't work. I tried following the video's instructions with "isDivisible" ,which didn't work. Then I turned the video's example into "isNotDivisible", changed some stuff, and submitted, which didn't work. I'm very confused.

divisible.swift
func isDivisible (dividend dividend: Int, divisor: Int) -> Bool {
    if dividend % divisor != 0 {
        return true
    } else {
        return false
    }
}
if let result = isNotDivisible(dividend: 10, divisor: 2) {
    print("Divisible")
} else {
    print("Not Divisible")
}

1 Answer

Hi Swiftdev

The challenge asks you to create a function called isNotDivisible that does the opposite of isDivisible. All you need is:

func isNotDivisible(#dividend: Int, #divisor: Int) -> Bool {
    return !isDivisible(dividend: dividend, divisor: divisor)
}

Florin