ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

Issue with adding and removing classes to change background images #265

Closed merubin closed 8 years ago

merubin commented 8 years ago

I am having an issue where I cannot swap my images for a element. I can do it by actually changing the background-image css tag, but I want to swap the class based on the state of my game. I have 7 .gif images for the various states of the game.

screen shot 2016-09-17 at 9 13 51 pm

The HTML is initalized and set to level zero image and will load the proper image as the level class is also part of the

container element.

screen shot 2016-09-17 at 9 16 45 pm

The js code to do the swap is the setHangLvl method:

screen shot 2016-09-17 at 9 11 14 pm

In the debugger, I see the class added, but the but the old class still remains. Here is a screen shot of the window:

screen shot 2016-09-17 at 9 04 28 pm

I did a push of my code at this point.
the github url to my repository is here Any help would be appreciated. Thanks, Mike

amaseda commented 8 years ago

Does anything change if, in .removeClass, you wrap lvl-1 in parentheses? Wondering if it could be an order of operations issue.

merubin commented 8 years ago

I tried the "()" and It still did not work, then I simplified the method so it would be easier to debug and step through it with the debugger. That led me to find out that the operator precedence was correct and did not need the parens. But it led me to find out I had misspelled the class name. Thank you for the reply! This issue is now solved but it opened up another one that I can find out. The issue was a typo where the class defined had a "-" and I was using an "_" underscore to change it. I don't know how many times I looked at it but getting away for a few hours then coming back opened my eyes. The bigger problem I have is I made an assumption that the class I need to remove is lvl-1 which is true but in my testing where I send in levels not in sequence or perhaps a reset of the game where we go back to zero it won't be true. for now I will just make a circular assumption that the states of the game go in order from 0-6 then when we go to reset the game we can set it back to zero and delete six. Probably better would be to find out what classes the element has and just delete it if I can figure that out.