Newer
Older
2023-c121119 / timer.js
@C121119A C121119A on 9 Nov 2023 890 bytes Update timer.js
(() => {
    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);
})();