“Cor aleatória por EventListener Clique” Respostas de código

Cor aleatória por EventListener Clique

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

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

function changeBackground() {
  const rndCol = `rgb(${random(255)}, ${random(255)}, ${random(255)})`;
  document.body.style.backgroundColor = rndCol;
}

btn.addEventListener('click', changeBackground);
Grumpy Gerbil

Cor aleatória por EventListener Clique

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

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

function changeBackground() {
  const rndCol = `rgb(${random(255)}, ${random(255)}, ${random(255)})`;
  document.body.style.backgroundColor = rndCol;
}

btn.addEventListener('click', changeBackground);
Grumpy Gerbil

Respostas semelhantes a “Cor aleatória por EventListener Clique”

Perguntas semelhantes a “Cor aleatória por EventListener Clique”

Mais respostas relacionadas para “Cor aleatória por EventListener Clique” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código