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

Laurie Cai
5,391 PointsHow to return boolean value from a function?
func isPositive(number: Int) -> Bool {
if number < 0 {
let isPositive = false
} else if number >= 0 {
let isPositive = true
}
return isPositive
}
isPositive(number: 6)
isPositive(number: -2)
The errors I'm getting are:
- Initialization of immutable value 'isPositive' was never used
- Cannot convert return expression of type '(Int) -> Bool' to return type 'Bool'
3 Answers

Laurie Cai
5,391 PointsFigured it out! Posting here in case it might help others:
func isPositive(number: Int) -> Bool {
if number < 0 {
return false
} else {
return true
}
}

james south
Front End Web Development Techdegree Graduate 33,271 Pointsi think the error is that your internal variable has the same name as the function itself. try a different variable name.

Laurie Cai
5,391 PointsChanged the function name:
func test(number: Int) -> Bool {
if number < 0 {
let isPositive = false
} else if number >= 0 {
let isPositive = true
}
return isPositive
}
The error returned is
- Use of unresolved identifier 'isPositive'

Inokentiy Kadilov
28,532 Pointsfunc isPositive(number: Int) -> Bool {
var isPositive = true
if number < 0 {
isPositive = false
} else if number >= 0 {
isPositive = true
}
return isPositive
}
isPositive(number: 6)
isPositive(number: -2)