[MIT Open-Source] - Can Someone Look At My Project's JavaScript Source Code(Game)?

Hi,

I personally hand built from the ground this JavaScript/HTML5 Web 2D video game.
Can some programmers here quickly look over the JavaScript source code?
I typed all code into JetBrain’s “WebStorm” IDE on Linux Mint 21.3 Cinnamon OS.

Source code is clean and is currently hosted on BitBucket site below:
https://bitbucket.org/jesseleepalser/t-crisis_v_firefox_110percent_ai/src/main/

Source code 100% free open-source cross-platform with the MIT software license.
I am not professionally trained in JavaScript so I did ALOT of Googling.

Any criticisms and/or suggestions for improvement is highly welcomed.
I did my best, but I need to do a little bit better.

Let me know, thanks!

NOTE - Beta should be uploaded no later than Monday (2024-05-13).

Jesse Lee

1 Like

Well, my first stop was your index.html and noticed it didn’t have a closing </html> tag. Then I noticed you are using an inline style for the div right above it for font family. I probably would move that to your index.css. Inline styles are more and more looked down on unless absolutely necessary.

Is this mobile friendly? I would suggest always putting in the following meta tag in your head as it helps instruct mobile browsers to size properly…

<meta name="viewport" content="width=device-width, initial-scale=1.0">

As for the JavaScript itself, it could use a bit more polish. Here are some tips on increasing readability and making your JS cleaner…

  1. Use proper and descriptive variable names. For example your data.js has variables temp, tempTwo and tempThree. In that same file in other functions you have variables like ca, c.

  2. Look for repetition and see if you can simplify using loops. In your data.js file I also see things like…

DataClassObject.HighScoresLevel[gameMode][0] = 10;
DataClassObject.HighScoresLevel[gameMode][1] = 9;
DataClassObject.HighScoresLevel[gameMode][2] = 8;
DataClassObject.HighScoresLevel[gameMode][3] = 7;
DataClassObject.HighScoresLevel[gameMode][4] = 6;
DataClassObject.HighScoresLevel[gameMode][5] = 5;
DataClassObject.HighScoresLevel[gameMode][6] = 4;
DataClassObject.HighScoresLevel[gameMode][7] = 3;
DataClassObject.HighScoresLevel[gameMode][8] = 2;
DataClassObject.HighScoresLevel[gameMode][9] = 1;

How might you do that using a loop?

  1. Keep your coding conventions consistent. If you are going to concatenate some items together, don’t smash them together with a + sign in one situation and then in the next line give proper spacing around the symbol. I recommend always putting a space on both sides of operators as it makes it easier to read overall and contributes to good “spacial rhythm”

  2. Last quick mention I will make is that you should be very skeptical of your use of the userAgent string. The browsers (lead by Chrome) are actually severely hampering that string in order to phase it out in favor of client hints. So eventually they will break on you.

Take these tips and move through your code base for further clean up. Once you have done that, you can certainly come back here and we can offer more tips.

Good luck. :slight_smile:

P.S. Bonus tip: Don’t put in a bunch of //------ style comments. They just add noise and don’t do anything for readability.

1 Like