First apologies for starting a new thread. It’s nearly 3 weeks and after several false starts, I keep thinking this is it!! But I seem to run in to same problem with my Simon Game.
The challenges work fine but click responses seem to develop a mind of their own after a few clicks.
May be
1 - I should be using buttons rather than event listners or
2 - I have got a completely wrong approach
3 - there is a simple error in my logic and I can not see the wood for the trees
4 - It’s a complete mess and I should start again
I am hoping it’s 3.
Please do have a look and see if you can help. The code is liittered with console.log lines. At one stage I thought I may as many console.log lines as lines code.
BTW, I have taken out all checks from strict Mode so that I may be able to pinpoint the error.
So far, no luck.
Thanks
Hey Mahesh,
I used buttons and mine works with less code. Maybe someone else will be more helpful than me and find a bug, but I just tested your app and it seems to be unable to repeat a consistent sequence. There is more than one way to skin a cat though, and your front end looks great.
Did it seem to develop this bug at a certain time or did you code everything in one go?
Thanks for responding. I have been at it for so long that I am not sure. I got the css and lightup sequence going couple months back. Got stuck and went ahead finished pomodoro and tic-tac-toe.
I think the eventlistener is getting ahead of itself.
I am just going thro’ and see if I can control it by checking for number of clicks.
Length of code just illustrates my lack of knowledge of javascript. Still a newbie.
I think this bit of code may be where your problems lie:
while (count <= round && clickCounter) {
colorSequence();
var mainTimeOut = setTimeout(setTop, 1000 * count, colorLit);
count++;
}
setTimeout(function() {
clearTimeout(mainTimeOut);
}, 100);
This while
loop takes almost no time to complete, and each time it’s redeclaring the mainTimeOut
variable. After the few milliseconds it takes to complete, the code moves on to the setTimeout
function, which clears the one timer it can reach after 1/10 of a second.
These two concepts aren’t exclusive, but you definitely shouldn’t be using button elements for this.
If you start over every time a problem seems insurmountable, you’ll never get anything done. Only restart a project when you know that you’d spend more time fixing the problem rather than starting over. At the very least, don’t delete your current code because it can serve as a reference if you do decide to start anew.
1 Like
I think you have put your finger on it.
I , just, added an addition check (clickCounter) to make sure all clicks are completed.
I think I have spent lot more time on this than I should but am only redoing this particular function.
I must admit I had not considered the while-loop being the problem.
I think I will go away and see if I can do it another way.
Thanks a lot.
Finally, managed to complete this project. Amazing how a little error in variable declaration and one misdirection in function path gets one going round in circles. Thanks for your help. Completion of Simon game completes my first part of the journey. Great achievement for a guy who turned 74, 10 days ago
2 Likes
Great job- can you provide some guidance how yo solved the following:
I created an objected with stores the function of the computer function for changing colors and audio
- I created Player moves and function for color and audio
- I create two SEPARATE arrays which store the moves of the Computer and Player
1 - comparing the Player Move vs Computer moves -
2. - Awaiting Player to enter moves…
here is my code link - http://codepen.io/docwali777/pen/aBzGNe?editors=1010
thanks
Hi. I am the wrong guy to ask. Just a novice who took nearly 3 weeks to get the game going. It seems you are on the right track.
I did it differently.
I just produced one random array which displayed the required color sequence. I then used same counter to check user clicks.
Good luck