(() => { var timer = null, count = 5, msgArea = null; function countdown() { count--; if (count==0) { alert("ぼかあああああああああん"); } else { msgArea.innerText = `爆発まであと ${count}秒` timer = setTimeout(countdown, 1000); } } function stop() { clearTimeout(timer); document.body.style.background = "#e99"; msgArea.innerText = "世界は救われた"; msgArea.style.fontSize = "200%"; msgArea.style.textAlign = "center"; } function init() { let divs = document.querySelectorAll("div"); msgArea = document.getElementById("message"); if (divs.length == 0) { alert("divがないよ!"); return; } let answer = Math.floor(Math.random()*10) console.log(`当たりは${answer+1}だよ`) atari = divs[answer]; atari.addEventListener("click", stop); timer = setTimeout(countdown, 1000); }; document.addEventListener("DOMContentLoaded", init); })();