<p id="output">
抽選結果
</p>
<button id="byUser">自分で指定</button>
<hr />
<p>
ブックマークレット登録用リンク <br />
👉 <a href="javascript:document.write(((array) => array[Math.floor(Math.random() * array.length)])(window.prompt('/ 区切りで指定').split('/')));" title="抽選くん ブックマークレット"><code>javascript:document.write(((array) => array[Math.floor(Math.random() * array.length)])(window.prompt('/ 区切りで指定').split('/')));</code></a>
</p>
function chooseOne(array) {
const one = ((array) => array[Math.floor(Math.random() * array.length)])(array);
document.getElementById('output').textContent = `[${array.join(', ')}] => ${one}`;
}
document.getElementById('byUser')
.addEventListener('click', () => chooseOne( window.prompt('"/" 区切りで指定').split('/') ));
chooseOne(['りんご', 'ごりら', 'らくだ']);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.