How to join lines to get a shape

share your views about the fiddle in this discussion Line segment coordinates i want to achieve same thing i our fiddle on which i am working