Newer
Older
2022-yuya / time.js
function CountDown(){
     var count = 1,
         infobox = document.getElementById("start"),
         atari = document.getElementsByTagName("div"),
         res = document.getElementById("result"),
         high = document.getElementById("high"),
         hit = Math.floor(Math.random()*6);
    
 function countdown(){
 	atari[hit].innerHTML = count;
        atari[hit].addEventListener("click",drop); 
 }
 function drop(){
 	atari[hit].innerHTML = "";
 	atari[hit].removeEventListener("click",drop);
 	count +=1;
 	if(count<21){
 	random();
 	}else{ result();
 	}
 }
 function random(){
 	  hit = Math.floor(Math.random()*6);
 	  countdown();
 }
function starts(){
        start = performance.now();
	infobox.removeEventListener("click",starts);
	countdown();
}
 function result(){
 	end = performance.now();
 	var time = (end-start)/1000;
 	res.innerHTML = "記録:"+time+"秒";
 	if(time<10){
 		high.innerHTML = "Congratulations! 10秒切り達成!!";
 	}
 }
     infobox.addEventListener("click",starts);
    }
document.addEventListener("DOMContentLoaded",CountDown);