js random hex color 1

js random hex color

'#'+Math.floor(Math.random()*16777215).toString(16);

Here is what the above code is Doing:
1. We’re creating a variable called ‘color’ and setting it equal to a string.
2. The string is a concatenation of the following:
a. A pound sign
b. A random number between 0 and 16777215
c. The random number converted to a string in base 16
3. We’re then returning the value of the ‘color’ variable.

Similar Posts