Skip to content

Instantly share code, notes, and snippets.

@shamdasani
Created October 17, 2016 01:27
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 shamdasani/981b734ed91a70d0fe840dc0e38236aa to your computer and use it in GitHub Desktop.
Save shamdasani/981b734ed91a70d0fe840dc0e38236aa to your computer and use it in GitHub Desktop.
// generator function
function getColor() {
return '#' + Math.random().toString(16).slice(2, 8);
}
// sets background color style
function setBackground() {
var bgColor = getColor();
document.body.style.background = bgColor;
}
// runs function on click
document.body.onkeyup = function(e){
if(e.keyCode == 32){
setBackground();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment