DEV Community

Prakhar Tandon
Prakhar Tandon

Posted on • Edited on

Random Colour Generator JS

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, it will randomly assign a new colour to the body of HTML page.
I am sharing my GitHub repository link for the same,which contains these functions in "script.js"
1) getRandomColor()
2) getRandomColorLight()
3) getRandomColorDark()
I would recommend you to have a look at it.

https://github.com/prakhart111/ColorFlipper

Image description

Hope You liked it!
and comment down your way to do the same.
Follow me on:
Twitter : https://twitter.com/PrakharTandon29
GitHub : https://github.com/prakhart111

Top comments (9)

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.