ga-wdi-exercises / project1

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

issue with memory game: stop event temporarily #220

Closed iamanissa closed 8 years ago

iamanissa commented 8 years ago

I tried to add stopPropogation, cancelBubble and preventDefault . I expected that after the active class was assigned to two divs, clicking on other cards would do nothing. User can still click on all cards and all clicked divs are still given the active class instead. My repo link is https://github.com/SuperJones/project1 and my question is about lines 18-27 : creating a function that will check if two divs have active class and if so, stop click event from firing.

RobertAKARobin commented 8 years ago

Check this out:

https://github.com/ga-wdi-lessons/bronze-silver-gold/blob/master/example/gold.js#L12

The event listener always fires -- but it doesn't actually do anything unless the element's class is blank and the hasWinner variable is falsy.

A big part of web development is "faking" things like this!

iamanissa commented 8 years ago

I sort of understand. I tried to ignore the firing and try something different by just adding a classname that would change the color back to gray in css. but every time I clicked a card it would keep adding the new classname over and over. In your example, in your example you compared it to blank, if I have an important class, I don't want my class to be blank. I will try fiddling with having it equal my singular class and see if I can implement the 'fake out'. Closing this and if other issues arrive I will submit new issue.

RobertAKARobin commented 8 years ago

It also doesn't need to be a class. That's just one example. You could have some kind of a global variable instead, like hasWinner in this case.