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
Mikkel Storch
1,955 PointsPrintln Function Index?
Hello I am doing the isDivisible exercise in Swift. As you can see in the second if statement I'm trying to get the first index (15) from isDivisble printed out and the "Is divisible with" the second index in the isDivisible function. Do anyone know if thats possible? Just thought it would become a nicer output than the video suggest. Thanks!
func isDivisble (divedend: Int, divisor: Int) -> Bool? {
if divedend % divisor == 0 {
return true
} else {
return nil
}
}
if let result = isDivisble(15, 3) {
println("\(result(0)) is divisible with \(result(1))")
}
miguelcastro2
Courses Plus Student 6,573 Pointsmiguelcastro2
Courses Plus Student 6,573 PointsThe result variable is Boolean as your function return statement indicates and a Boolean only returns true or false. A Boolean does not contain an index, an array contains an index because an index represents the position of an item in the array. One way to achieve what you are trying to do is by setting your dividend and divisor as variables: