How to generate a random RGB color code in JavaScript

1 Answer

0 votes
function generateRandomRGBColor() {
  const red = Math.floor(Math.random() * 256);
  const green = Math.floor(Math.random() * 256);
  const blue = Math.floor(Math.random() * 256);

  console.log(`Random RGB Color: rgb(${red}, ${green}, ${blue})`);
}

generateRandomRGBColor();




/*
run:

Random RGB Color: rgb(223, 132, 67)

*/

 



answered Oct 9, 2025 by avibootz
edited Oct 9, 2025 by avibootz
...