Skip to content

Instantly share code, notes, and snippets.

@gilbertoquinteroA
Created June 25, 2018 10:19
Show Gist options
  • Save gilbertoquinteroA/480bc6951f535b09299189c75cab0ef3 to your computer and use it in GitHub Desktop.
Save gilbertoquinteroA/480bc6951f535b09299189c75cab0ef3 to your computer and use it in GitHub Desktop.
background random with JS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>background random with JS</title>
script src="js.js"</>
</head>
<body>
<button>Change color</button>
</body>
</html>
var btn = document.querySelector('button');
function random(number) {
return Math.floor(Math.random()*(number+1));
}
btn.onclick = function() {
var rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
document.body.style.backgroundColor = rndCol;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment