function CountDown() {
    var count = 3;
    var tmID;
    var infobox = document.getElementById("info");
    var start = document.getElementById("start");
    var clear = document.getElementById("clear");

    start.addEventListener("click", startCountDown, false);

    function countDown() {
      if (--count == 0) {
        infobox.innerHTML = "残念！時間切れ！";
      } else {
        infobox.innerHTML = count + "秒前";
        tmID = setTimeout(countDown, 1000); 
      }
    }
 
function startCountDown() {
  tmID = setTimeout(countDown, 500);
  var list = document.getElementsByTagName('div');
  for (let i of list){
    i.removeEventListener("click", startCountDown, false);
    clear.addEventListener('click', stopCountDown);
  }
}
 
function stopCountDown() {
  if (count >= 0) {
    clearTimeout(tmID);
    infobox.innerHTML = "成功";
  }
}
 
};
document.addEventListener("DOMContentLoaded", CountDown, false);