What I learned on this mini-project.
Here, the click
event is important in determining the outcome of the game, therefore we need to protect from false clicks that can be be mimicked through cheeky javascript code.
Using the isTrusted
property allows you to confirm that the event was generated by a user action.
https://gist.github.com/0936725d9e87676b9a9d6f89c622c692
The code above, will return if the event was not a product of user action (not through a script).
This technique was used to prevent the same hole from being used twice in a row. It's important to return the value in the randomHole
method, so that it can be used recursively.
https://gist.github.com/8f40b02e6691b8967ed2276d0b0ff46f
Here, the lastHole
variable will be assigned to the randomly generated hole. If the following call generates the same hole, the randomHole
will be called again until lastHole != hole
.