Now, let’s work on the function that will be called if the user clicks the key
G on the keyboard.
Implement and export the function
handleKeyPress(term, state) in the
For the reasons that you’ll understand in the next task, we need to make it a closure. In other words
handleKeyPress(term, state) should return another function with 3 parameters (name, matches, data).
We’re only interested in the key that was pressed, and it’s stored as a code in the field
You can use
String.fromCharCode() to convert the code of the key into the actual symbol.
If the key is equal to
g it should increment the property
of the parameter
state by 1.
P.S. Remember that we import
config only into
solution.js and then forward it as
The names of these internal parameters could be chosen differently, it’s the structure that very important here.
If you have any issues with it, you can ask for community help below the post.
Feel free to help others if you’ve already solved the task.