0

Random color generator

const getRandomColor = () => {
  let letters = '0123456789ABCDEF';
  let color = '#';
  for (var i = 0; i < 6; i++) {
    color += letters[Math.floor(Math.random() * 16)];
  }
  return color;
}

const setRandomColor = () => {
  $("#colorpad").css("background-color", getRandomColor());
}

var button = document.querySelector('button');

button.addEventListener('click', () => {
  setRandomColor();
});
<div id="colorpad" style="width:300px;height:300px;background-color:#000">
</div>

<button>Random Color</button>
RUN
add comment
Suggest a different solution or add another example