const sfx = new Audio("audio/button-press.mp3"); export function DeckButton(name) { const elem = document.getElementById(`${name}-button`); const images = { up: `images/${name}-button-up.jpg`, down: `images/${name}-button-down.jpg` }; let state = "off"; const turnOn = function () { state = "on"; elem.src = images.down; }; const turnOff = function () { state = "off"; elem.src = images.up; }; return { state: () => state, toggle: (opts = {sound: true}) => { state === "off" ? turnOn(opts) : turnOff(opts); if (opts.sound) sfx.play(); } }; }