Two ways to generate random color - Daily JavaScript #5

I am 17 years old and a young passionate and self-taught frontend web developer and have an intention to become a successful developer. I usually write about JavaScript and Web Development and share some tips in the articles.
Why not make your own color generator π?
Method 1 - Long method
// Generate random color in hex format
const randomColor = () => {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
Method 2 - Short and Best Method
const randomColor = Math.floor(Math.random()*16777215).toString(16);
console.log("#" + randomColor)
Thank you for reading, have a nice day!
- Follow me on Twitter - @codewithsnowbit
- Subscribe me on YouTube - Code With SnowBit




