Nice work!
I think one change I’d make is to only use Math.random once and do it in a function that only returns a number between 0 and 256. Then I’d use that function inside the function randomRGB
specifically inside the string interpolation ${}
. For example:
rgb(${randColorNum()}, ${randColorNum()}, ${randColorNum()})
I like this kind of separation of concerns:
One function returns a number between 0 and 256
One function returns a color with rgb()
Also this part inside the event handler:
body.style.backgroundColor = randomRGB();
btn.style.backgroundColor = body.style.backgroundColor;
If both elements will share the same color then I’d make a variable called color.
const color = randomRGB();
body.style.backgroundColor = color;
btn.style.backgroundColor = color;
Otherwise if you want the button color to be different than the body BG color, then remove the color variable and just call the randomRGB() as the values for both the button and BG color.