r/learnjavascript • • Jul 03 '22

My first project!

226 Upvotes

28 comments sorted by

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!

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

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.

18

u/code_matter Jul 03 '22

Now, make it a list! So let’s say you want a color palette. You generate random color and when you want you “add” it to the list!

11

u/Dark_KnightPL04 Jul 03 '22

Thats a great idea! I will have to add that feature.

1

u/raveun Jul 04 '22

You’re one step away from dark/light mode toggle ;)

1

u/Dark_KnightPL04 Jul 04 '22

I am?

1

u/raveun Jul 05 '22

If you know how to store/get things in localstorage and you’re able to get users-prefer-color-scheme then you’re few steps away on stitching those together to make it into a light/dark toggle.

Check this out:

https://piccalil.li/tutorial/build-a-light-and-global-state-system/

1

u/Dark_KnightPL04 Jul 05 '22

Cool, thanks!

16

u/[deleted] Jul 03 '22

Add a memory feature so you can browse backwards through the colors.

1

u/david_ranch_dressing Jul 04 '22

To add to this, I would use Local Storage.

7

u/theneddyflanders Jul 03 '22

congrats! stay consistent, you’ll be amazed at what you can do in just a couple of months!

4

u/Dark_KnightPL04 Jul 03 '22

I was amazed by this! Cant wait to do more complex projects.

4

u/Cardmin Jul 03 '22

Awesome! Great first project!

4

u/Nile-99 Jul 03 '22

If you know how it works and you can build it from scratch on your own then Great Job! Now keep learning, keep grinding

3

u/Beerbelly22 Jul 03 '22

I need this, with a setInterval of 500. murder my visitors

1

u/BRPelmder Jul 03 '22

Can you add a button to push once, switch colors every .5s or quicker. Bam you have a disco party app

1

u/Paleontologist_Worth Jul 04 '22

Great job! This is a fun project

1

u/[deleted] Jul 04 '22

I love it!

1

u/___s8n___ Jul 04 '22

nice job! keep going, keep learning

1

u/StONE_ROdGEr Jul 04 '22

Nice! Now try adding ‘transition: 1s’ to the CSS class that’s being updated each time 👍

1

u/Mylah016 Jul 05 '22

I love it :)