JSFiddle - React, Tailwind, and code Playground
by BaguetteSeeker
HTML
<h1 style="color: red">
<button id="idGen">
<span>Generate ID</span>
</button>
<span id="idOutput"></span>
</h1>
JavaScript
const charBase = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
const generateNewID = (charBase) => {
let res = "",
rdmIndex = "",
rdmNumber = "";
for (let x = 0; x < 12; x++) {
rdmNum = Math.random();
console.log("Num = " + rdmNum);
rdmIndex = Math.floor(rdmNum * (charBase.length - 1));
console.log(rdmIndex);
console.log(charBase[rdmIndex]);
res += charBase[rdmIndex];
}
console.log(res);
return res;
}
document.getElementById("idGen").addEventListener("click", () => {
document.getElementById("idOutput").textContent = generateNewID(charBase);
})