That’s a great point. If you start out with a definite objective like that, it’s going to be hard to get past the depression hump. I know for me I have to give myself more general objectives. So instead make a goal of learning how to code. You can find tons of lessons online that are aimed at teaching kids, and they typically have a gamification component to them. That quick hit of serotonin is what you need to stay with it. If, instead, you start out wanting to make a game app for your phone, you’ll quit when it gets too hard.
Sounds like you either need to establish better task parameters or you need to gain more experience programming.