(() => {
var timer = null, count = 3, 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 = "#";
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);
})();