<p id="randomId">randomId</p>
<p id="timestamp">randomId</p>
<p id="uuid">randomId</p>
const getElement = (selector) => document.querySelector(selector);
const innerText = (selector, fn) => getElement(selector).innerText = `${selector}:${fn()}`;
// methods
const randomId = () => Math.floor(Math.random() * 1000000);
const timestamp = () => Date.now();
const randomUUID = () => crypto.randomUUID();
// 注入到畫面
innerText('#randomId', () => randomId());
innerText('#timestamp', () => timestamp());
innerText('#uuid', () => randomUUID());
console.log(`randomId:${randomId()}`);
console.log('------')
console.log(`timestamp:${timestamp()}`);
console.log('------')
console.log(`UUID:${randomUUID()}`);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.