diff --git a/bokan.js b/bokan.js new file mode 100644 index 0000000..4c1a37d --- /dev/null +++ b/bokan.js @@ -0,0 +1,39 @@ +#!/usr/bin/env js + +(() => { + var timer = null, count = 5; msgArea = null; + function countdown() { + count --; + msgArea.innerText = `爆発まで あと${count}秒`; + if (count==0) { + alert("ボカーーーンドンガラガッシャーン"); + msgArea.innerText = `正解は ${answer+1} だったよ!`; + } else { + timer = setTimeout(countdown, 1000); //1秒待つ + } + } + function stop() { + clearTimeout(timer); + document.body.style.background = "#00ff00"; + msgArea.innerText = "世界は救われた"; + msgArea.style.fontSize = "200%"; + msgArea.style.fontWeight = "bold"; + } + 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]; + if (count>0) { + atari.addEventListener("click", stop); + timer = setTimeout(countdown, 1000); + } + }; + + document.addEventListener("DOMContentLoaded", init) +})(); +