Last active
August 10, 2021 18:12
-
-
Save clayadavis/ee44fadb8ea1db6d9629cde8f9eb7d18 to your computer and use it in GitHub Desktop.
Random die face
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const d6 = () => String.fromCodePoint(0x2680 + Math.floor(Math.random() * 6)) | |
function d6() { | |
const faceIdx = Math.floor(Math.random() * 6); | |
const codePoint = 0x2680 + faceIdx; | |
return String.fromCodePoint(codePoint) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
String.fromCharCode
also works here and has better browser compatibility.