Last active
June 24, 2021 14:58
-
-
Save ciamac-da/312bcac5b8dff18fc2282cdf29740baa to your computer and use it in GitHub Desktop.
This is how to to generate a random color HEX code
This file contains hidden or 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 decToHex = (number) => { | |
| return number.toString(16).padStart(2, "0") | |
| } | |
| const getRandomNumber = (min, max) => { | |
| min = Math.ceil(min) | |
| max = Math.floor(max); | |
| return Math.floor(Math.random() * (max - min + 1)) + min; | |
| } | |
| const generateRandomColor = () => { | |
| let hexCode = '#'; | |
| for (let i = 0; i < 3; i++) { | |
| hexCode += decToHex(getRandomNumber(0, 255)); | |
| } | |
| return console.log(hexCode); | |
| } | |
| generateRandomColor() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment