window.onclick = (event) => box.style.display = (event.target == window ) ? "none";
var changeBoxVisibility = show => {
box.style.display = show ? 'block' : 'none'
}
var showBox = () => changeBoxVisibility(true)
var hideBox = () => changeBoxVisibility(false)
var open = document.querySelector("#open");
var close = document.querySelector(".close");
open.onclick = showBox
close.onclick = hideBox
Array.from([open, box]).forEach(el => {
el.addEventListener('click', e => e.stopPropagation())
})
document.addEventListener('click', hideBox)