diff --git a/index.html b/index.html index 63ec94b..17ec28e 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,13 @@ metal pipe from metal pipe fallout sound effect videos

+

+ + +

+

+ +

diff --git a/index.js b/index.js index 91f2445..6fd5d12 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,10 @@ const pipefall = document.getElementById("pipefall"); const now = document.getElementById("play-now"); + const playAtRandom = document.getElementById("play-at-random"); + const randomChance = document.getElementById("random-chance"); + + playAtRandom.checked = false; const play = () => { console.log("pipefall!"); @@ -14,4 +18,24 @@ for (let pipe of document.querySelectorAll(".pipe")) { pipe.addEventListener("click", play); } + + function random(max) { + return Math.floor(Math.random() * max); + } + + let timeSincePlay = 0; + setInterval(() => { + if (playAtRandom.checked) { + timeSincePlay += 1; + if (timeSincePlay >= 60) { + const v = random(randomChance.value); + if (v === 0) { + play(); + timeSincePlay = 0; + } + } + } else { + timeSincePlay = 0; + } + }, 1000); })();