let clicksCount = 0;
let x1, x2, y1, y2;
function clickHandler(event) {
clicksCount++;
const coordinates = { x: event.pageX, y: event.pageY };
switch (clicksCount) {
case 1:
x1 = coordinates.x;
y1 = coordinates.y;
break;
case 2:
x2 = coordinates.x;
y2 = coordinates.y;
break;
default:
window.removeEventListener('click', clickHandler);
}
};
window.addEventListener('click', clickHandler);