You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's a little easy to "fudge" the game by clicking all over the place
indiscriminately. Lets keep track of "misses" so we can penalize the player
when they miss.
director.js
Define a missCount instance variable on the Director in the
constructor (initialize it to 0).
Attach a "click" handler to the director's el in the constructor.
Increment the director's missCount variable in the "click" handler.
Careful! Due to "event bubbling", this handler will be called even when
the player successfully whacs a mole. This makes sense, if you think about
it: when you click on a mole element, you are also clicking on the
director's "container" element. The event handler receives a special "event
object" as its first argument, and that object has a target property
which is the element that originally received the click. So:
this.el.addEventListener(function(event) {
// Here, `event.target` is the element that first got the click
});
...knowing that, can you find a way to only increment the missCount if
the click was really a "miss"?
Update the endGame method to remove the new event listener (we don't
want to keep incrementing the "miss" count if the user clicks on the
Director element after the game is over).
Update the end game "report" to also print the value of the missCount
variable at the end of the game.
We have a lot of -count variables now! It might be a good idea to keep these
a little more organized. Try changing the constructor to define an instance
variable called counts as an object with three attributes (whac, escape,
and miss), all initialized to 0. Update all the places you increment a count
accordingly (i.e. switch this.missCount++ to this.counts.miss++. Finally,
you can remove the existing count variables that you created in the previous
issues.
The text was updated successfully, but these errors were encountered:
It's a little easy to "fudge" the game by clicking all over the place
indiscriminately. Lets keep track of "misses" so we can penalize the player
when they miss.
director.js
Define a
missCount
instance variable on theDirector
in theconstructor (initialize it to 0).
Attach a "click" handler to the
director
'sel
in the constructor.Increment the
director
'smissCount
variable in the "click" handler.Careful! Due to "event bubbling", this handler will be called even when
the player successfully whacs a mole. This makes sense, if you think about
it: when you click on a mole element, you are also clicking on the
director's "container" element. The event handler receives a special "event
object" as its first argument, and that object has a
target
propertywhich is the element that originally received the click. So:
...knowing that, can you find a way to only increment the
missCount
ifthe click was really a "miss"?
Update the
endGame
method to remove the new event listener (we don'twant to keep incrementing the "miss" count if the user clicks on the
Director element after the game is over).
Update the end game "report" to also print the value of the
missCount
variable at the end of the game.
We have a lot of -
count
variables now! It might be a good idea to keep thesea little more organized. Try changing the constructor to define an instance
variable called
counts
as an object with three attributes (whac
,escape
,and
miss
), all initialized to 0. Update all the places you increment a countaccordingly (i.e. switch
this.missCount++
tothis.counts.miss++
. Finally,you can remove the existing
count
variables that you created in the previousissues.
The text was updated successfully, but these errors were encountered: