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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![jon kelson](https://uploads.teamtreehouse.com/production/profile-photos/3901132/micro_image.jpg)
jon kelson
5,149 PointswithRange range
Hi all, I'm getting a fault message with the perameters local and external for func surroundingPointsWith.. I've just writen this code exact I think from the video and he had no faults . its telling me i should not have the withRange and i should delete it to fix the problem.
struct Point { let x: Int let y: Int
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
}
}
}
let coordinatePoint = Point(x: 0, y: 0) coordinatePoint.x
1 Answer
![jcorum](https://uploads.teamtreehouse.com/production/profile-photos/4188262/micro_jgc_photo.jpg)
jcorum
71,830 PointsThe problems are (1) a missing curly brace and (2) a reversed curly brace:
struct Point {
let x: Int
let y: Int
func surroundingPointsWith(withRange range: Int = 1) -> [Point] {
var results: [Point] = []
for xCoord in (x-range)...(x+range){
for yCoord in (y-range)...(y+range) { //missing {
let coordinatePoint = Point(x: xCoord, y: yCoord)
results.append(coordinatePoint)
} //need } instead of {
}
return results
}
}
let coordinatePoint = Point(x: 0, y: 0)
coordinatePoint.x
jon kelson
5,149 Pointsjon kelson
5,149 PointsThanks I amended the curly braces but that didn't solve the problem . For some reason it didn't like the "with" part of the withRange . I tried it with lots of other Double words such as allRange etc and it worked fine . Haven't a clue why .
The errors saying 'with' implied for the first part of the method; did you mean to name this parameter 'range'.
Ok ! Just after writing the above I just deleted the space in between withRange and range and then put the space back in . It works fine now . Very strange !!!