For Loop in Unit 5 Lesson 3 causing issues with App


I am trying to make an app similar to the physical game whack a mole.

function moleLoop (){
timedLoop(3000, function(){
moleNum = randomNumber(1, 10);
console.log (moleNum);
displayMole ();
setTimeout (function () {
}, 2000);
if (score === 10) {
stopTimedLoop ();

Link to the project or level: []
What I expect to happen: [ Before I made a timed loop to loop the appearance of moles, I have code that states that when a mole is clicked, it gets set to hidden using the hideElement ID.

Does the setTimeout function work within a timed loop, or is there a different way to go about having them disappear after 2 seconds?

I also stated that when the score is equal to 10, it stops the timed loop, and eventually will start a faster-timed loop so the moles disappear faster. I attached the loop code, as well as the whole project for reference.]

What actually happens: [Now, once the mole appears, when clicked it carries out the function and adds a point like it is supposed to, but does not disappear, as it did before the loop was created.

Also, the loop works by showing the mole and changing the number as intended, but the Timeout function I have in the loop doesn’t seem to slow it down. ]
What I’ve tried: [I’ve tried to take out the loop and the program runs somewhat, but the hide & unhiding of the mole doesn’t function correctly and the 2nd faster loop doesn’t work. The more I add and take away the less I get with the coding. I am super confused. ]

Please help,

Hi @jangel,

Were you able to fix the issue? The game seems to work flawlessly and does exactly what you described you expect to happen. The moles disappear when clicked and the pace quickens after 10 points.

Let me know if this isn’t the case for you.

Also thanks for being so thorough with your description of the problem and for sharing the link - definitely helps with troubleshooting!


Hi Frank,

Thanks for the response, I think the network was our biggest issue here at my school. The student never said anything more about his app, and he has moved on to the next level! You are welcome, I believe the more we share, the better the results!

Happy Coding!