Create a random color based on a string using JavaScript

Today we’ll show you how to create a random color based on a string using JavaScript. Here we will create a rgb color based on the first character of a string.

How To Generate a Random Color in JavaScript, get rgb colour based on a string, JavaScript to generate random hex codes of color, string to color javascript, random light color javascript, random material color generator javascript example.

Why do we need it?

Sometimes we need to implement a functionality where we have to create an icon based on the user name. That icon contains the background color and first character of a string. Check the below image for your reference.

Output - Create a random color based on a string using JavaScript - Clue Mediator
Create a random color based on a string using JavaScript – Clue Mediator

Function to create a random color

Call a function

In the above code, we need to pass the string as a parameter and with the help of the above code we are returning the color in rgb format and the first character of the string in uppercase.

That’s it for today.
Thank you for reading. Happy Coding!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *