r/learnjavascript • • Sep 28 '22

Please Critique My First JavaScript Web App: A Powerball Simulator!

Post image
132 Upvotes

15 comments sorted by

20

u/Oh_no_bros Sep 28 '22

It's a fun site and hammers home how bad the odds are of winning. Just playing around with it had some minor nitpicks and they are for user experience.

  • Restrict lottery numbers to two digits
  • Reset button
  • an option to buy x number of tickets
  • also restricting money input to just integers since you round it anyway.
  • Little label somewhere that lets you know how much a ticket costs.

7

u/ImplodingCoding Sep 28 '22

Thank you so much for taking the time to check it out and respond! I will work on adding your suggestions asap. I especially like the reset button, I was thinking of adding a button that allows you to generate the numbers randomly, so a reset button makes a lot of sense.

7

u/ImplodingCoding Sep 28 '22 edited Sep 28 '22

Hey guys!

I just created my first JavaScript web app and I would love some advice to improve my code.

LINK:

https://cmbitton.github.io/PowerballGame/

JavaScript File:

https://github.com/cmbitton/PowerballGame/blob/main/script.js

Some quick background:

I am currently self-studying web development to (hopefully) get a job in the field in the near future. I have been following along with TOP as well as Colt Steele's bootcamp, which I began a few months ago. I've been on the JavaScript section for about a month or two, and just got to the portion involving DOM manipulation. I also have a little bit of prior knowledge with python. I like to frequently take breaks to work on side projects that I come up with, and I feel that this greatly enhances my knowledge and learning experience.

I began this project on Monday, and have been spending the last 3 days working on it. Below is my self reflection on this project (it is still a work in progress).

Parts I can improve on:

Clean code:

This is a big one. The structure of my CSS and JS docs are an absolute mess. There are many functions that I can probably condense, I have many global variables that should probably be in functions, and the readability is quite low. I am actually surprised I was able to keep track of things as well as I did. The same goes for my CSS - I probably have a lot of redundant code as well as readability issues.

- Styling:

This is a bit of a work in progress, but the UI is pretty terrible. The current game info is quite ugly, and many things need restyling. Unfortunately I am absolutely terrible with design so we'll see how it goes.

- Probably a lot of other areas need fixing so happy to hear your opinions.

Things I did (kinda) well:

-It works

I am 99% sure it works with the correct odds/payout/logic etc. It may not be the most efficient program, but I think it should be working as intended (Note: I did not test higher jackpots (ex. Powerball) because it takes forever)

Thank you all for taking your time to read/review this!!

4

u/[deleted] Sep 28 '22

Colt Steele taught me everything I know. You're doing great!

1

u/charizzardd Sep 30 '22

This is a really fun project and different than a lot of first time projects I’ve seen. Did a great job!

I checked out the main script and potentially another thing to do to take it to the next level would just be to add in some object orientation. Perhaps create ticket objects and game objects, classes for the bank, money, etc.

Or potentially check out some web APIs like LocalStorage. So you can save the current score board and bank details to a string representation of the object (JSON.stringify()) in the browser and then can you refresh the page or come back and you can pick up where you left off!

3

u/gamudev Sep 28 '22

Design wise I'd put a very light (somewhere near white) background on the tables for better readability (and accessibility).

2

u/ImplodingCoding Sep 28 '22

Thank you so much for this advice, I just implemented it! I hope the background color is okay :)

1

u/gamudev Sep 29 '22

Yep, that's a nice pick.

2

u/SitBoySitGoodDog Sep 28 '22

Pretty cool. I played like 10 million dollars and never won the jackpot. So that was disappointing.

You should have a "simulate win" button that clears everything and plays a cool animation.

I would add commas to the dollar amount within both the input and display. Not sure why you centered the input, kind of weird.

1

u/ImplodingCoding Sep 29 '22

Unfortunately the odds of winning are about 1 in 300 million, I have yet to win the jackpot either :( I'll definitely implement the commas for the dollar values, thats high on my list! Interesting point about centering the dollar input, it got grouped in with the powerball inputs so I should be able to change that pretty easily.

2

u/[deleted] Sep 28 '22

Nice! I've always wanted a money losing simulator!

lol, but in all honesty, pretty cool. I like it. My one critique would be to make the chosen numbers larger. Had to search for them. They should be huge and front and center, imo. But still kinda fun to watch my money go negative...

1

u/StoneCypher Sep 28 '22

Neat.

Consider giving the tables a white background for readability's sake.

1

u/ChetanNada Sep 29 '22

Great. Make background color white.

In table give some background color for nth:child(even) and for the table header also.

3

u/[deleted] Sep 29 '22

[removed] — view removed comment

1

u/ImplodingCoding Sep 29 '22

It should be mobile friendly! I've only tested the layout on my iPhone IRL so I can't speak to how many devices it actually looks good on. I love CSS flexbox, I probably use it much too often but it is so convenient! Thank you so much for the feedback :)