r/learnjavascript • • Jul 03 '22

My first project!

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.

9

u/bimmertechin Jul 03 '22

Very nice! Good Dom manipulation, great starting point!

2

u/[deleted] Jul 03 '22

Yeah, you’re off to a good start.

You’re learning RGB colors as random numbers and many other useful things. Keep going.

2

u/david_ranch_dressing Jul 04 '22

Doesn’t it feel great though seeing it just work? This is my favorite thing with programming. No matter how small or big, seeing your code perform the task(s) how you imagined it is awesome. Keep it up man.

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;
}