Simon game- I've been stuck for 5 hours with a simple bug

I normally ask in the chats for help but I thought I would also post here as it’s quite a large project for someone to skim through.

The game runs as expected (although quite slowly on codepen), you can play it through and win with no problems.

However, if you fail on the first loop then, after the ‘game over’ alert pop up, the game continues playing. I noticed this after adding trying to add a lives system and it really put a spanner in the works.

However, if you fail on any loop after the first, then it doesn’t show this behaviour.

I know it must be a very simple hole in my logic that more than likely is a problem with the ‘start game’ button but I honestly have exhausted every option that I’m aware of (as I said, hours of trying).

The code is here, thanks in advance,

If you need me to explain anything then I’ll be happy to (hopefullly my code is clean enough to understand, even if it’s in dire need of refactoring).

EDIT: To clarify just a tiny bit more. If you deliberately fail on the first loop after starting the game, then look at the level counter (the number below) you will notice it increment and another iteration of the game will play. Instead, it should stop and stay at level 1.

SOLVED

The problem was - exhaustion!

About an hour ago I was trying to solve this bug while having loaded the wrong JS file (I saved a backup and forgot to change the script tag). All I needed to do was uncomment the resetGame() function and now it’s fine.

I think I’m gonna get some sleep :).

1 Like

Nice catch!

That was actually going to be my suggestion - walk away for a while. I cannot count the number of times I’ve stayed up late in frustration agonizing over what should be a simple fix. Finally throw in the towel and come back in the morning and have it fixed in five minutes …

Often all you need is a little space between you and the problem to see it properly.

Eeeexactly. I’ve been coding for about 12 hours and exhaustion is really showing. I’m making sloppy mistakes like writing “=” instead of “==” and not returning values. But I’ve finished everything now minus adding the sounds (which I hope is easy); take a look if you want!

Night everyone :).