I've just starting to learn JavaScript, So I know only a few things about it. I have searched this question and I found the right code for it that works fine with hexadecimal color format. But before that i was trying sth on my own, Can you help me to turn it to an RGB color generator. Every time I add this code to my page it won't work.
document.getElementById("myButton").onclick = function() {
var r =Math.random();
r = 255*r;
r = Math.floor(r);
var g =Math.random();
g = 255*g;
g = Math.floor(g);
var b =Math.random();
b = 255*b;
b = Math.floor(b);
var color= "rgb(" + r +"," + g +"," +b ")";
document.getElementById("myDiv").style.background: color;
}
Aucun commentaire:
Enregistrer un commentaire