Two factors determine what a React Component renders:
Props
- properties passed into the component from it's parent.State
- the internal state of a component
If you haven't already, read the React docs to get a better sense of these two concepts.
In this challenge, we'll be building a Whack-A-Mole game - this exercise will serve as a gentle introduction to state and props.
Note: Make sure to run npm install
from the app's root to get the necessary node modules on your local machine.
The game "engine" has already been created. The state of the top-level component, App.js
, contains two items:
- dens - an array of objects that are a representation of the "holes" in the whack-a-mole game.
- points - an integer that contains the number of times a mole was whacked/clicked.
Inspect App.js
and attempt to understand the game engine logic - this may help you in achieving the objectives.
- Modify the
props
that are passed intoMole.js
and theMole.js
component itself so that the Mole image only appears when the isMoleVisible property of the appropriate den object is set to true.
- Modify
Mole.js
so that points are incremented whenever a visible mole is clicked. - Add comments to the
startGame()
,getDensState()
, andonMoleWhacked()
functions that explain what the code is doing.