Just started learning JS and decided to make a simple game using JS basics. Would like to get some feedback. Thanks
HI @DeiSen !
A few notes from me.
This is non coding related, but for games it is best to include instructions on how to play the game so the player knows what to do.
It is doesn’t have to be long, but a short description would be nice.
Here are my notes specifically for the code.
The first thing, is that you don’t want to use
var in your code because es6 introduced
I found a couple of good beginner articles so you can learn about the differences between
const. It also talks about the issues using
My second is concerned with naming of variables.
There are a few places where there are inconsistencies with naming.
let finscr = document.getElementById("finalScore"); let bestscr = document.getElementById("bestScore"); let winScr = document.getElementById("winScr"); let gameScr = document.getElementById("game_screen");
All those variables should be in camelCase for consistency and best practices.
You want to develop the habit of good practices early on
Also, I would personally change those names from
The more descriptive you can be the better.
Remember that other developers will be looking at your code and you want really descriptive names so other developers don’t have to guess as to what they are
My advice goes for your naming of functions.
For some functions you use camelCase and others you are using PascalCase.
I would just use camelCase for all of those function names.
There also seem to be instances of repetition like here.
let winScr = document.getElementById("winScr"); let gameScr = document.getElementById("game_screen");
It would be better if you declared those variables at the top using
const since those values don’t seem to be changing.
Then you can just reference those variables throughout your code and cut down on repetition.
You want to be careful about unnecessary repetition in code because that can introduce bugs in your code.
Hope that helps!