Created
June 25, 2018 10:19
-
-
Save gilbertoquinteroA/480bc6951f535b09299189c75cab0ef3 to your computer and use it in GitHub Desktop.
background random with JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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