Simple Vanilla JS game while learning

Just started learning JS and decided to make a simple game using JS basics. Would like to get some feedback. Thanks

HI @DeiSen !

Congrats on creating your first game with javascript. :slight_smile:

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 let and const.
I found a couple of good beginner articles so you can learn about the differences between var, let and const. It also talks about the issues using var

My second is concerned with naming of variables.
There are a few places where there are inconsistencies with naming.
For example:

    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 :slight_smile:
Also, I would personally change those names from gameScr to gameScreen or finalScore.
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 :slight_smile:

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. :slight_smile:

Hope that helps!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.