“Losowy kolor według EventListener Click” Kod odpowiedzi

Losowy kolor według EventListener Click

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

Losowy kolor według EventListener Click

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

Odpowiedzi podobne do “Losowy kolor według EventListener Click”

Pytania podobne do “Losowy kolor według EventListener Click”

Więcej pokrewnych odpowiedzi na “Losowy kolor według EventListener Click” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu