diff --git a/kujibiki.js b/kujibiki.js index c810881..0d59486 100644 --- a/kujibiki.js +++ b/kujibiki.js @@ -2,7 +2,7 @@ function CountDown() { var count = 4, tmID, - hit = Math.floor(Math.random()*10+1); + hit = Math.floor(Math.random()*10); areas = document.querySelectorAll("div"), button = document.getElementById("start"), infobox = document.getElementById("result"); @@ -10,11 +10,8 @@ if (--count == 0) { infobox.innerHTML = "失敗…"; infobox.setAttribute("class", "failure") - for (let i of areas) { - if (i.textContent == hit) { - i.removeEventListener("click", stopCountDown, false); - } - } + areas[hit].removeEventListener("click", stopCountDown, false); + } else { infobox.innerHTML = count + "秒前"; tmID = setTimeout(countDown, 1000); @@ -23,19 +20,15 @@ function startCountDown() { tmID = setTimeout(countDown, 1000); button.removeEventListener("click", startCountDown, false); - for (let i of areas) { - if (i.textContent == hit) { - i.addEventListener("click", stopCountDown, false); - } - } + areas[hit].addEventListener("click", stopCountDown, false); + console.log(hit+1+"番だよ"); } function stopCountDown() { clearTimeout(tmID); infobox.innerHTML = "成功!!"; infobox.setAttribute("class", "success"); - areas.removeEventListener("click", stopCountDown, false); } button.addEventListener("click", startCountDown, false); } document.addEventListener("DOMContentLoaded", CountDown, false); -})(); \ No newline at end of file +})();