function CountDown() {
var count = 4, tmID, infobox = document.getElementById("start"), suc = document.getElementById("suc"),fin = document.getElementById("fin");
function countDown() {
if (--count == 0) {
infobox.innerHTML = "時間切れ";
suc.removeEventListener("click", stopCountDown, false);
} else {
fin.innerHTML = count + "秒前";
tmID = setTimeout(countDown, 1000);
}
}
function startCountDown() {
tmID = setTimeout(countDown, 1000);
infobox.removeEventListener("click", startCountDown, false);
infobox.addEventListener("click", stopCountDown, false);
}
function stopCountDown() {
if (count >= 0){
clearTimeout(tmID);
infobox.innerHTML = "成功";
}
fin.innerHTML = "終了";
suc.innerHTML = "正解";
suc.removeEventListener("click", stopCountDown, false);
}
infobox.addEventListener("click", startCountDown, false);
};
document.addEventListener("DOMContentLoaded", CountDown, false);