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

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
  }
}