Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Functions and Optionals Optionals Review: Functions

Marco Aguilar
Marco Aguilar
888 Points

Functions and Optionals Last challenge

Cannot solve code

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

1 Answer

Ryan Jin
Ryan Jin
15,337 Points

You have to write the code where the function also returns true. Your code only allows the function to return false, but what if it is not divisible, then the function doesn't return anything but the requirement specifies that the function has to return a boolean. And also, the challenge asks you to check is the are the two numbers not divisible, so you should return true if it is not divisible, and return false if it is not divisible. So your code should look something like this:

func isNotDivisible(#dividend: Int, #divisor: Int) -> Bool {
  if dividend % divisor != 0 {
    return true
  } else {
    return false
  }
}