Answers for "javascript-change color onclick()"

0

javascript-change color onclick()

const btn = document.querySelector('button');

function random(number) {
  return Math.floor(Math.random() * (number+1));
}

btn.onclick = function() {
  const rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
  document.body.style.backgroundColor = rndCol;
}
Posted by: Guest on June-29-2021

Code answers related to "javascript-change color onclick()"

Browse Popular Code Answers by Language