Published on January 26, 2024By DeveloperBreeze
// Function to calculate the distance between two points in a 2D plane
function calculateDistance(x1, y1, x2, y2) {
const deltaX = x2 - x1;
const deltaY = y2 - y1;
return Math.sqrt(deltaX ** 2 + deltaY ** 2);
}
// Calculate and log the distance between two points (e.g., (0, 0) and (3, 4))
const distance = calculateDistance(0, 0, 3, 4);
console.log('Distance Between Two Points:', distance);
Comments
Please log in to leave a comment.