# Edit in JSFiddle

```function computePi() {
var diameter = parseInt(\$('#input').val());
var inCircle = 0;
var inSquare = diameter * diameter;

for(var y = 0; y < diameter; y++)
for(var x = 0; x < diameter; x++)
if(inside(x,y))
inCircle++;

document.getElementById('report').innerHTML =
"<table>" +
"<tr><td>Diameter</td><td>" + diameter + "</td></tr>" +
"<tr><td>inCircle</td><td>" + inCircle + "</td></tr>" +
"<tr><td>inSquare</td><td>" + inSquare + "</td></tr>" +
"<tr><td>Pi</td><td>" + 4 * (inCircle / inSquare) + "</td></tr>" +
"</table>";

function inside(x, y) {
var r = diameter/2
,   xr = x-r
,   yr = y-r;
return xr*xr+yr*yr<=r*r;
}

}

computePi();

\$('#input').change(computePi);```
```<div id="report"></div>

<input type="text" id="input" value="10000" />

<p>One can argue that this is not sampling of PI. This is the actuall PI of the given discrete circle. Every actual existing circle have to be made of measurable points (and not an infinite numbers of points). And as such they have an actual final value of PI.</p>```