Unit 3 Lesson 22 debug game

Line 134 function zombie movement: Once the zombies x position is == 110, zombies should disappear and game over should show up.

Line 264 function speed: once shooter has so many kills If kills are > 2 then the zombies should get progressively faster.

I’ve tried a few things a nothing seems to be working. Also, if you could give me any tips on how to use the debug console or watcher to help solve problems like this, I would appreciate it.


One of the big issues with using the == is that it has to be equal.
Depending on how the x position of the zombie is being updated, the x position may never be equal to 110.
I tell the students to use >= or a combination of >= and <= to get a range of values to trigger the if statement.

Looks like the zombies are speeding up with the increasing score.

In general, people assume they know the value of a variable at a certain time, the watchers help to verify that. Many times the assumption of the value and the actual value at a certain time are different.

I also like to add console.log statements into an if statement to see if that branch of code ever gets run.

if (zombie2.x == 110) {
   console.log("yay!. I made it to this branch!") ;
    gameOver.visible = 1;
    deadSoldier.visible = 1;
    soldier.visible = 0;
    soldier.y = 1000;
    block.visible = 1;
    zombie2.visible = 0;

Hopefully that helps. Let us know how it goes!