function main() { var count = 4,tmID,button = document.getElementById("start"), atari = document.getElementById("true"),finish = document.getElementById("info"); function CountDown(){ if (--count == 0) { finish.innerHTML = "終了"; atari.removeEventListener("click", stopCountDown, false); } else { finish.innerHTML = count + "秒前"; tmID = setTimeout(CountDown, 1000); } } function startCountDown() { tmID = setTimeout(CountDown, 1000);/*1000ms=1秒*/ button.removeEventListener("click", startCountDown, false); atari.addEventListener("click", stopCountDown, false); } function stopCountDown() { if (count >= 0) { clearTimeout(tmID); button.innerHTML = "爆発阻止成功です!"; } finish.innerHTML = "終了"; atari.innerHTML = "爆弾みーっけ"; atari.removeEventListener("click", stopCountDown, false); } button.addEventListener("click", startCountDown, false); }; document.addEventListener("DOMContentLoaded", main, false);