Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(x1, y1, x2, y2) {
- let distanceAB = ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
- let result = Math.sqrt(distanceAB);
- console.log(result);
- }
- solve(2.34, 15.66, -13.55, -2.9985);
- /*
- Write a JS function that calculates the distance between two points by given x and y coordinates.
- The input comes as four number elements in the format x1, y1, x2, y2.
- Each pair of elements are the coordinates of a point in 2D space.
- The output should be returned as a result of your function.
- */
Advertisement
Add Comment
Please, Sign In to add comment