diff --git a/bomu.css b/bomu.css index ec51928..aed02b0 100644 --- a/bomu.css +++ b/bomu.css @@ -1,2 +1,2 @@ -body {background: tomato;} +body {background: White;} div p {text-align: center; border: 2px yellow solid; width: 50%; margin: 0 auto;} diff --git a/bomu.html b/bomu.html index 1898870..ef0d3d2 100644 --- a/bomu.html +++ b/bomu.html @@ -3,7 +3,8 @@ 爆発までにクリック
- + + diff --git a/bomu.js b/bomu.js index e84dd0d..4188b20 100644 --- a/bomu.js +++ b/bomu.js @@ -1,11 +1,31 @@ (()=>{ var count = 3, tmID, infobox = document.getElementById("timeout"); - function countDown(e) { + function countDown() { if (--count == 0) { infobox.innerHTML = "ぼかーん"; + } else { + msgArea.innerText = `爆発まであと ${count}秒` + timer = setTimeout(countdown, 1000); + } } - function startCountDown() { - document.body.addEventListener("click", dblSize); + function stop() { + clearTimeout(timer); + document.body.style.background = "#e99"; + msgArea.innerText = "世界は救われた"; + msgArea.style.fontSize = "200%"; + msgArea.style.textAlign = "center"; } - document.addEventListener("DOMContentLoaded", init); + function init() { + let divs = document.querySelectorAll("div"); + msgArea = document.getElementById("message"); + if (divs.length == 0) { + alert("divがないよ!"); return; + } + let answer = Math.floor(Math.random()*10) + console.log(`当たりは${answer+1}だよ`) + atari = divs[answer]; + atari.addEventListener("click", stop); + timer = setTimeout(countdown, 1000); + }; + document.addEventListener("DOMContentLoaded", init); })();