DEV Community

awsomebro
awsomebro

Posted on

Color changer in javascript

Javascript

function RandomColor() {
var Color = "#" + Math.floor(Math.random() * 16777215).toString(16);
return Color;
//color will be freshly served
}
function Change() {
document.body.style.backgroundColor = RandomColor(); // -> #e1ac94
someDiv.style.color = Color();
}

Oldest comments (4)

Collapse
 
mykelcodex profile image
Oke Michael

nice

Collapse
 
awsomebro profile image
awsomebro

thanks bro

Collapse
 
fyrfli profile image
Camille

What happens when you get a colour like #09df6c? I found that the leading zero always got stripped away.

Collapse
 
tzwel profile image
tzwel

at least learn to properly format your code before writing something like this