} status Element.innerText='Generating $(numImpression} impressions' ; impression Timeout = setTimeout ( () => { closeWindows () ; }, closeTime * 1000);//close the windows after the specified time in milliseconds } function closeWindow () { generating = false; windows.forEach(window) => { if window.close (); } }); document.getElementById('status').innerText = 'Impression completed'; } function stopImpression () { if (generating { clear Timeout(impressionTimeout); closeWindows(); } else { document.getElementById('status').innerText = 'Impression generation stopped' ; } } }