The handler is ready, so we need to connect it with the keypress event.

But before that we need to improve the init function. It accepts a single parameter and should call on it:

  • clear()
  • hideCursor()
  • grabInput()
    The function names are self-explanatory and will help us start working with keyboard events.

Inside of the startMiningGame, after calling init, call the function term.on('event', handler).
This function accepts 2 parameters. The first one is a string. As we want to handle keyboard events,
we’ll set it to 'key'.

The second one is a callback function which has 3 parameters (name, matches, data).
We’ve already implemented the appropriate closure on the previous stage. Time to use it!

This task is part of the Full-Stack JavaScript Course.
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.