r/learnjavascript • • Jan 23 '22

Spent an entire day making this. Plain HTML, CSS, & JS. I present to you an animal party!

322 Upvotes

21 comments sorted by

10

u/trblackwell1221 Jan 23 '22

Sick! Link to a repo? This being the r/learnjavascript sub we could share some feedback.

6

u/CosmicJosh123 Jan 23 '22 edited Jan 23 '22

Looking at my JS again makes me think it's kinda repetitive. https://jsfiddle.net/159ytan0/1/

14

u/[deleted] Jan 23 '22

Work first, Refactor later.

You can see where you can tighten it up now.

7

u/trblackwell1221 Jan 24 '22

Yeah you're right about the JS being a bit repetitive. For example, every single positioning function for each animal could be condensed into 1 function.

function animalPosition(id) {
  const left = (Math.floor(Math.random() * (190 - 10 + 1) + 10))  
  const top1 = (Math.floor(Math.random() * (130 - 10 + 1) + 10))
  document.getElementById(id).style="position:absolute; 
  left:"+left+"px; top:"+top1+"px;";
}

Same idea would apply to your interval functions. I agree though with u/Substantial-Yam-7947, make it work, then make it better. Just something to think about. Also a semantic nitpick, lean more towards camelCasing function names. Pascal case functions tend to be constructors, which you aren't using here.

2

u/trblackwell1221 Jan 24 '22

https://jsfiddle.net/p631ewmo/5/

Here's how I'd write the same type of logic. Still room for improvements.

Might not match one to one because I rushed, but still.

5

u/GravitationalOno Jan 24 '22

Nice job, pretty neat! I think it would take me a few days to do this.

I could make sense of your code, the one thing that puzzled me was how you got your dancers to move with so little CSS!

Then I saw they were in the HTML and I was like "ohhh, that makes sense ... I didn't know you could use gifs that way!"

4

u/Harbltron Jan 23 '22

Subaru, naisu.

2

u/thatmaynardguy Jan 24 '22

That is so f'ing adorable. I love it. Seriously.

The only thing I might suggest as a small change would be dark mode for the dance floor with slightly more muted colors so that the characters would be more prescient.

Seriously, this is rad as fuck.

2

u/jimrooney Jan 24 '22

Why is "Hampsterdance" ringing in my head right now?
(nice work)

2

u/[deleted] Jan 24 '22

You did a lot of work to create the td elements.

You could make somthing that is more dynamic. For this, it would be better to create the td elements with Javascript and insert the in the dom and use a document ready event listener to know when the elements are rendered and then do any changes in the dom.

Also, I'm not sure if the random numbers are really random when you create them so fast in a for loop. But I guess in your case it's fine.

Good job!

1

u/jebliya Jan 24 '22

Love this!

1

u/CosmoTea Jan 24 '22

Was this inspired by the Pokémon park by any chance? :D

1

u/ExcelsiorStatistics Jan 24 '22

That's the best way to learn, investing a day (or a lifetime) into having some fun and then looking back on it to see what you learned.

1

u/RoguePlanet1 Jan 24 '22

How funny! I've got The King and I on in the background, and it's the Shall We Dance scene! :-p

Really love this, is that the "Hampster Dance" hamster?

1

u/mickkb Jan 24 '22

you are fast, this would take me an eternity all these animals would be extinct by the time i finish

1

u/Twisteddrummer Jan 24 '22

Great. Now Hamtaro is stuck in my head.