Newer
Older
ryuei / 10.js
@Ryuei Ryuei on 1 Nov 2022 1012 bytes add file
function CountDown() {
    var count = 4, tmID, infobox = document.getElementById("start"), atari = document.getElementById("true"),finish = document.getElementById("info");
    function CountDown() {
	if (--count == 0) {
	    finish.innerHTML = "終了";
	} else {
	    finish.innerHTML = count + "秒前";
	    tmID = setTimeout(CountDown, 1000);
	}
    }
    function startCountDown() {
	tmID = setTimeout(CountDown, 1000);
	infobox.removeEventListener("click", startCountDown, false);
	atari.addEventListener("click", stopCountDown, false);
    }
    function stopCountDown() {
        if (count >= 0) {
            clearTimeout(tmID);
            infobox.innerHTML = "爆発阻止成功です!";
        }
        
	clearTimeout(tmID);
	finish.innerHTML = "終了";
	atari.innerHTML = "爆弾みーっけ";
	atari.removeEventListener("click", stopCountDown, false);
    }
    infobox.addEventListener("click", startCountDown, false);    
};
document.addEventListener("DOMContentLoaded", CountDown, false);