+ 1
Can anyone explain this Random color generator function ?
function generateRandomColor() { return '#' + Math.floor(Math.random() * 163427).toString(16);
4 Respostas
+ 4
random*16 returns a number bt. 0 and 163426.
u need it as hex value.
Therefore number is converted to eg #a1b2c3.
toString(16) converts from base 10 to base 16.
Finally prefix # is added.
+ 3
Check out these links about Math.random and String.toString
https://www.w3schools.com/JS/js_random.asp
https://www.w3schools.com/jsref/jsref_tostring_string.asp
+ 1
Frogged thx sir , can you explain it in brife please 🙏..
+ 1
Ipang thx sir 🙏