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 trialJuan Coetzer
891 PointsKeep on getting errors
I keep on getting 4 errors:
- in my first for loop it says: "Cannot call value of non-function type 'Int'"
- at the curly bracket at the end of the first for loop it says: "Expected ',' separator"
- at the return statement, it says: "Expected expression in list of expressions"
- the curly bracket ending the func gives an error: "Expected ')' in expression list
Don't understand, my code is exactly the same as Pasan's code. Here is my code:
struct Point { let x: Int = 2 let y: Int = 2
func surroundingPointsWith(withRange range: Int = 1) -> [Point] {
var results: [Point] = []
for xCoord in (x-range...(x+range) {
for yCoord in (y-range)...(y+range) {
let coordinatePoint = Point(x: xCoord, y: yCoord)
results.append(coordinatePoint)
}
}
return results
}
}
1 Answer
Juan Coetzer
891 PointsNever mind, I found my error thank you. /*my first for loop was missing a bracket for xCoord in (x-range...(x+range) should be: */
for xCoord in (x-range)...(x+range)
//my code now works!