Motivation isn’t fuel, it is only a catalyst. It is not and should not be the only thing that sustain your action.
You have to hold yourself accountable to accomplish things. It’s the same for anything in life. You are responsible for your own actions and you bear those consequences. There isn’t always this magical surge within you that propels you to work, sometimes, the promise you made to yourself has to be enough. That is the mindset you need to have to keep yourself on track. It’s a grind, even if it is something you love.
It’d be better if you do some self-reflection to sort out why you are not motivate or why you are. Literally write it down if you have to. When you want to code, or learn about coding, what prompted you to do so? What do you accomplished when you are motivated? When you stop or choose to do something else rather than learning or code, what is the main reason? What excuses are you making to yourself? When you identify reasons of your actions, it becomes easier to modulate and optimize your behavior.
If big vague goal seems unreachable, then break it up into concrete reachable goal. Instead of “I want to start free lancing in 2019”, do “I want to replicate the ESPN home page layout with CSS Flexbox in a week”, or “I want to create a reusable calendar component using React in a month”. Further break down these goals into tasks you can check off, like gather assets, read this post on CSS Tricks, create basic mock layout…etc.