Last active
May 9, 2020 12:31
-
-
Save rodrigoramirez93/737574cf7fff47ea10a46f4d88667a77 to your computer and use it in GitHub Desktop.
Change color randomly in javascript
This file contains hidden or 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
//live example at: https://playcode.io/448394 | |
var makeColors = () => { | |
var minNum = 0; | |
var maxNum = 9; | |
var minLet = 65; | |
var maxLet = 71; | |
function randomNumber() { | |
return (Math.floor(Math.random() * (+maxNum - +minNum)) + +minNum).toString(); | |
}; | |
function randomLetter() { | |
return String.fromCharCode((Math.floor(Math.random() * (+maxLet - +minLet)) + +minLet)); | |
}; | |
var color = []; | |
color[0] = '#'; | |
for (let i = 1; i < 8; i++) { | |
color[i] = randomNumber(); | |
color[i + 1] = randomLetter(); | |
} | |
return color.join(''); | |
} | |
var miliseconds = 200; | |
window.setInterval(function () { | |
document.body.style = 'background-color: ' + makeColors() + ''; | |
}, miliseconds); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment