function calcDistance(x1, y1, x2, y2){ //calculate dx and dy dx = x2 - x1; dy = y2 - y1; //calculate distance dist = Math.sqrt((dx*dx) + (dy*dy)); return dist; } // end calcDistance
The calcDistance function is fairly universal across languages (though the syntax will vary, the concept is universal.) To see the JavaScript code for the other parts of this specific program, use the view source command of your browser.