Newer
Older
2022-yuya / kujibiki.js
@takano yuya takano yuya on 5 Nov 2022 939 bytes Update kujibiki.js
function CountDown(){
 var count = 4 , tmID, infobox = document.getElementById("start"),
             hit = Math.floor(Math.random()*10),
             atari = document.querySelectorAll("div"),
             res = document.getElementById("result");
 function countdown(){
  if(--count==0){
   res.innerHTML = "はずれ。";
   infobox.innerHTML ="時間切れ";
   atari[hit].removeEventListener("click", stopCountDown, false);
   } else {
       infobox.innerHTML = count + "秒前";
       tmID = setTimeout(countdown, 1000);
      }
 }
 function startCountDown(){
  tmID = setTimeout(countdown, 0);
  infobox.removeEventListener("click", startCountDown, false);
  atari[hit].addEventListener("click", stopCountDown, false);
 }
 function stopCountDown(){
  clearTimeout(tmID);
  res.innerHTML = "あたり!";
 }
 infobox.addEventListener("click", startCountDown, false);
}
document.addEventListener("DOMContentLoaded", CountDown, false);