# So I made a Javascript game and I need some feedback

**URL:** <https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655>\
**Category:** I Built This\
**Created:** [April 13, 2022, 11:39pm UTC](https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655 "2022-04-13T23:39:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aclixion](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aclixion/32/48555_2.png) [@Aclixion](https://forum.freecodecamp.org/u/Aclixion)\
**Post date:** [April 13, 2022, 11:39pm UTC](https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655/1 "2022-04-13T23:39:04Z")

</div>

Link to Project: [GitHub - Aclixion/Bubble-Popper](https://github.com/Aclixion/Bubble-Popper)

I was bored one day so I made this little game you can play to pass some time and relieve stress. Here are some things I’m looking for:

1. What are some best practices I should follow? What should I do to improve my code?
2. How should I organize my Javascript code?
3. What are some GitHub best practices I should follow?

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [April 14, 2022, 1:05am UTC](https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655/2 "2022-04-14T01:05:46Z")

</div>

HI @Aclixion !

> [@Aclixion](#):
>
> I was bored one day so I made this little game you can play to pass some time and relieve stress.

I think it would be great if we could play the game and test it out.  
Do you have this deployed somewhere?  
If not, that would be a good start.  
Something like github pages would work.

> [@Aclixion](#):
>
> What are some best practices I should follow? What should I do to improve my code?

Some of naming for files is a little unconventional.  
For example, instead of `javascript.js` you could something more common like `index.js` or `script.js`.

In your css, I would suggest removing the import statement and using the google font link tag in your html instead.  
There are a lot of discussions about imports in css and you can read about it here.

> <https://stackoverflow.com/questions/11709625/is-using-import-declarations-a-bad-practice>

> [@Aclixion](#):
>
> How should I organize my Javascript code?

I think your code structure is pretty easy to follow.  
You have all of your variables at the top, followed by your functions and then the eventlistener.

> [@Aclixion](#):
>
> What are some GitHub best practices I should follow?

Typically for readmes, you would use a markdown file extension (.md) instead of a text file (.txt)

Also, since this is a game, I would suggest adding a link in the readme and possibly some screenshots from the game.

Lastly, I would start getting in the habit of writing more descriptive commit messages.  
Right now you are just have one commit message and you are solely focused on personal projects.  
But eventually you will be working on a team or open source environment and providing descriptive messages will provide good context on what you worked on.

Here are some good resources to look into.

> **[How to Write Good Commit Messages: A Practical Git Guide](https://www.freecodecamp.org/news/writing-good-commit-messages-a-practical-guide/)**
>
> To create a useful revision history, teams should first agree on a commit message convention to use. This also applies to personal projects. Recently on Hashnode \[https://hashnode.com\] I asked, "Which commit message convention do you use at work?"...

> **[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)**
>
> A specification for adding human and machine readable meaning to commit messages

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Aclixion](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aclixion/32/48555_2.png) [@Aclixion](https://forum.freecodecamp.org/u/Aclixion)\
**Post date:** [April 14, 2022, 5:23pm UTC](https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655/4 "2022-04-14T17:23:55Z")

</div>

Thanks! This really helped!

May I also request some suggestions on my Javascript in general? For example, is there any unecessary and redundant lines of code that I can remove? Sorry for all the trouble!

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [April 14, 2022, 9:13pm UTC](https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655/5 "2022-04-14T21:13:16Z")

</div>

I think everything looks clean.

You might consider declaring and initialize these variables at the top

```auto
let score = 0;
let secondsLeft = 10;

```

---

<div class="post-metadata">

**Author:** ![bbsmooth](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bbsmooth/32/203556_2.png) [@bbsmooth](https://forum.freecodecamp.org/u/bbsmooth)\
**Post date:** [April 14, 2022, 9:34pm UTC](https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655/6 "2022-04-14T21:34:10Z")

</div>

I just wanted to chime in and say that I am pleasantly surprised that I was able to play this game using the keyboard only. To be honest, I was expecting a bunch of `<div>`s with a click handler attached for the bubbles and instead you are using `<button>`s, which automatically make it keyboard accessible. Great job!

---

<div class="post-metadata">

**Author:** ![Aclixion](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aclixion/32/48555_2.png) [@Aclixion](https://forum.freecodecamp.org/u/Aclixion)\
**Post date:** [April 15, 2022, 12:00am UTC](https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655/8 "2022-04-15T00:00:55Z")

</div>

Thank you! Honestly, I didn’t know that fact when I was working on my project.

I also needed a simple way to make sure that there is a way to turn off the buttons so that they cannot be clicked if the game ends. This is the main reason why I used buttons, because it has the `disabled` attributes.

---

<div class="post-metadata">

**Author:** ![jenovs](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jenovs/32/60963_2.png) [@jenovs](https://forum.freecodecamp.org/u/jenovs)\
**Post date:** [April 15, 2022, 8:27am UTC](https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655/9 "2022-04-15T08:27:16Z")

</div>

The loooooong list of 156 HTML buttons can be replaced with a JS loop:

```auto
const mainSectionEl = document.querySelector('.main-section');

const allBubbles = Array.from({ length: 156 }, () => {
  const bubbleEl = document.createElement('button');
  bubbleEl.classList.add('bubble');
  bubbleEl.setAttribute('disabled', true);
  return bubbleEl;
});

allBubbles.forEach((el) => {
  mainSectionEl.appendChild(el);
});

```

This way you can easily change the size of the grid.

In `startGame()` you don’t need `if`s to enable all buttons:

```auto
  // Enables all bubbles
  for (bubble of allBubbles) {
    bubble.disabled = false;
    bubble.classList.remove('popped');
  }

```

Same in the `endGame()`:

```auto
  // Disables all bubbles
  for (bubble of allBubbles) {
    bubble.disabled = true;
  }

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [October 14, 2022, 8:27pm UTC](https://forum.freecodecamp.org/t/so-i-made-a-javascript-game-and-i-need-some-feedback/504655/10 "2022-10-14T20:27:23Z")

</div>

Closed on October 14, 2022, 8:27pm UTC

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