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 trialCody Adkins
7,260 PointsHelp with my code
Not sure what I am doing wrong here...
let numbers = [Int](0...50)
// Enter your code below
func isOdd(number: Int) -> Bool {
return number % 2 == 0
}
2 Answers
Paul Brazell
14,371 PointsYou are not returning an appropriate return type of Bool. You need to check if the number is Odd. If it is, then you return true. Else return false.
let numbers = [Int](0...50)
// Enter your code below
func isOdd(number: Int) -> Bool {
if number % 2 != 0 {
return true
}
else {
return false
}
}
jcorum
71,830 PointsPaul's right. But here's an opportunity to practice what some call Boolean Zen:
func isOdd(n: Int) -> Bool {
return n % 2 != 0
}
Since n % 2 != 0 is going to be either true or false for any n, just return it, rather than returning true or false in an if... else...
Paul Brazell
14,371 PointsGreat tip! Will be sure to remember this in the future!
Cody Adkins
7,260 PointsCody Adkins
7,260 PointsThank you!