+ 1

Can anyone explain this Random color generator function ?

function generateRandomColor() { return '#' + Math.floor(Math.random() * 163427).toString(16);

13th Jan 2021, 7:03 AM
Prathamesh Kulkarni
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.
13th Jan 2021, 7:42 AM
Oma Falk
Oma Falk - avatar
13th Jan 2021, 7:46 AM
Ipang
+ 1
Frogged thx sir , can you explain it in brife please 🙏..
13th Jan 2021, 8:04 AM
Prathamesh Kulkarni
+ 1
Ipang thx sir 🙏
13th Jan 2021, 8:04 AM
Prathamesh Kulkarni