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 Closures Closures and Closure Expressions Using Filter

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

Define a function, named isOdd, to check if a number is odd. The function takes a number and returns either true or fals

Hi guys, i am stuck in here, please help!

Thanks in advance!

filter.swift
let numbers = [Int](0...50)

// Enter your code below
func isOdd(i: Int) -> Bool {
  if (i in numbers % 2 == 0) {
    return True
  } 
  else {
    return False
  }
}
Michael ninh
Michael ninh
Courses Plus Student 2,176 Points
<p>

func isOdd(i: Int) -> Bool{
    return i % 2 != 0
}

1 Answer

func isOdd(i: Int) -> Bool{ return i % 2 != 0 }

How did you know that... Amazing.