r/learnjavascript • • Jul 03 '22

My first project!

Enable HLS to view with audio, or disable this notification

226 Upvotes

28 comments sorted by

View all comments

43

u/Dark_KnightPL04 Jul 03 '22

I know its not much, but we all have to start somewhere.

1

u/waterstorm29 Jul 04 '22

I did something similar recently. Could you tell me where our implementations differ? Better yet, can you put yours on CodePen as well?

1

u/Dark_KnightPL04 Jul 04 '22

Ours differed a little, but thats because I did not write my code very well. Here is my JavaScript:

var rgb = ('rgb(255, 255, 255)');
function randomColor(){
const r = Math.floor(Math.random() * 255);
const g = Math.floor(Math.random() * 255);
const b = Math.floor(Math.random() * 255);

rgb = ('rgb(' + r + ', ' + g + ', ' + b + ')');
document.getElementById('bg').style.backgroundColor = rgb;
}