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 Exercise: isDivisible function

boris said
boris said
3,607 Points

Is this a better or worse way to do this

func isDivisble(#numberOne: Int, #numberTwo: Int) -> Bool? {
var status = false

    if numberOne % numberTwo == 0 {
      status = true
    }

    if status == true {
        println("Is Divisble")
        return status
    } else {
        println("Is not Divisble")
        return nil
    }
}

isDivisble(numberOne: 20, numberTwo: 4)

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hey Boris:

Here is the beautiful thing about coding, there is no better or worse way of writing something, if you get the results you needed then you did good. Think of it as a fingerprint, everyone has a different one. When it comes to coding each person has different styles of getting to the same result. So if your code works, kudos.

Keep coding