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

pleas help

dont know how

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

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi haydensteed,

You have a few things wrong with your code, they are:

  1. Your parameters dividend and divisor should be named, i.e. have the pound/hash symbol before them
  2. let ha = isDivisible is invalid code as isDivisible isn't a valid variable name
  3. Your IF statement should be returning true
func isNotDivisible(#dividend: Int, #divisor: Int) -> Bool { 
  if dividend % divisor != 0 { 
    return true
  }

  return false
}

Happy coding!

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello there.

I see that there is a little confusion, maybe the code challenge instruction are a bit long and this leads to it.

What the challenge wants you to do is actually creating an "opposite" function to the isDivisible function that we have.

I recommend you to start by following the isDivisible function code at first, because the condition to check will be very similar. What changes is the outcome, as we are now checking if the dividend is NOT divisible by the divisor.

Also, please note that there is no need to declare a new variable here.

Vittorio

Srinivasan Senthil
Srinivasan Senthil
2,266 Points

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

}

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

This is another way of writing. Basically i just removed the # symbol.

symbol is to say if the alias name and parameter name are the same. We can then use # symbol to denote them.

You are thinking wrong by this line: let ha = isDivisible What you have understood is that the bool value of isDivisible function, which could be "True" OR "False" is passed into the variable ha.

Yes, you can do it, but the issue is your function has other Parameter and the argument within them

Next, the second last line: ha = false you can do this because your variable ha is a constant. You will have to change the datatype.