# checking a point is in polygon

```function insidePoly(poly, pointx, pointy) {
var i, j;
var inside = false;
for (i = 0, j = poly.length - 1; i < poly.length; j = i++) {
if(((poly[i].y > pointy) != (poly[j].y > pointy)) && (pointx < (poly[j].x-poly[i].x) * (pointy-poly[i].y) / (poly[j].y-poly[i].y) + poly[i].x) ) inside = !inside;
}
return inside;
}
```

Here is what the above code is Doing:
1. It's creating a function called insidePoly that takes three arguments:
a. poly: an array of points that define the polygon
b. pointx: the x coordinate of the point we're testing
c. pointy: the y coordinate of the point we're testing
2. It's creating a variable called inside and setting it to false.
3. It's creating a for loop that loops through each point in the polygon.
4. It's creating a variable called j and setting it to the last point in the polygon.
5. It's creating an if statement that checks to see if the point we're testing is inside the polygon.
6. If the point is inside the polygon, it sets the inside variable to true.
7. It returns the inside variable.