Skip to content

Instantly share code, notes, and snippets.

@jcunanan05
Created June 1, 2018 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcunanan05/26ce5e4ddaaed865744a16759855b1bd to your computer and use it in GitHub Desktop.
Save jcunanan05/26ce5e4ddaaed865744a16759855b1bd to your computer and use it in GitHub Desktop.
Javascript code for spouting rgb colors
function randomNumber(maxNum) {
return Math.floor((maxNum * Math.random()) + 1);
}
function randomRgb() {
var r = randomNumber(256),
g = randomNumber(256),
b = randomNumber(256);
return 'rgb(' +
r + ', ' +
g + ', ' +
b +
')';
}
function changeBackgroundColor(element) {
element.style.backgroundColor = randomRgb();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment