DEV Community

Random Colour Generator JS

Prakhar Tandon on December 17, 2021

Hey Folks! Today I came up with this colour generator function. This can be a really cool projects for newbie developers! Well as the name suggests...
Collapse
 
j471n profile image
Jatin Sharma

You should use s.length instead of 16 in line:8. So you don't have to hardcode.

Collapse
 
prakhart111 profile image
Prakhar Tandon

Yes! thanks for the suggestion:)

Collapse
 
devfranpr profile image
DevFranPR

It wouldn't be better to randomize 3 numbers from 0 to 255 convert to hex and concat them?

Collapse
 
prakhart111 profile image
Prakhar Tandon

Hey DevFranPR,
Yeah, this one will also work fine.
Actually there are several possible ways to perform this operation, will try to enlist them all in my next article.
Stay Tuned !

Collapse
 
devfranpr profile image
DevFranPR

Nice! Follow

Thread Thread
 
prakhart111 profile image
Prakhar Tandon

And Share this article !
Connect with me on twitter as well ( link in the post )

 
prakhart111 profile image
Prakhar Tandon

Thanks for the precise and nice explaination man, I myself wasn't aware of this ES6 approach.

Thread Thread
 
mukul1312 profile image
Mukul1312

Thanks @lukeshiru for such a detailed explanation.

Collapse
 
mukul1312 profile image
Mukul1312

Can you please explain this approach, specially getRangedRandomColor function.