JSFiddle - React, Tailwind, and code Playground
by heera
HTML
<div id="outputColor">RGB</div>
<br />
<div id="outputColorHex">HEX</div>
CSS
#outputColor, #outputColorHex
{
height: 100px;
width: 100px;
background-color: rgb(0,0,0);
}
JavaScript
part1 = Math.floor(Math.random() * (255 - 0 + 1)) + 0;
part2 = Math.floor(Math.random() * (255 - 0 + 1)) + 0;
part3 = Math.floor(Math.random() * (255 - 0 + 1)) + 0;
currentColor = "rgb(" + part1 + ", " + part2 + ", " + part3 + ")";
currentColorHex="#"+(part1).toString(16)+(part2).toString(16)+(part3).toString(16);
document.getElementById("outputColor").style.backgroundColor=currentColor;
document.getElementById("outputColorHex").style.backgroundColor=currentColorHex;