In this article from 2016, James Clear investigates motivation:

Why do we stay motivated to reach some goals, but not others? Why do we say we want something, but give up on it after a few days? What is the difference between the areas where we naturally stay motivated and those where we give up?

The answer, which is obvious when we think about it, is that we need appropriate challenges in our lives:

Tasks that are significantly below your current abilities are boring. Tasks that are significantly beyond your current abilities are discouraging. But tasks that are right on the border of success and failure are incredibly motivating to our human brains. We want nothing more than to master a skill just beyond our current horizon.

We can call this phenomenonThe Goldilocks Rule. The Goldilocks Rule states that humans experience peak motivation when working on tasks that are right on the edge of their current abilities. Not too hard. Not too easy. Just right.

But he doesn’t stop there. He goes on to talk about Mihaly Csikszentmihalyi’s notion of peak performance, or ‘flow’ states:

In order to reach this state of peak performance… you not only need to work on challenges at the right degree of difficulty, but also measure your immediate progress. As psychologist Jonathan Haidt explains, one of the keys to reaching a flow state is that “you get immediate feedback about how you are doing at each step.”

Video games are great at inducing flow states; traditional classroom-based learning experiences, not so much. The key is to create these experiences yourself by finding optimum challenge and immediate feedback.

Source: Lifehacker