I used to have the exact same mentality. However, I had to make myself interested in building random projects because of the feeling I had at the end of completing one. When I complete a project, I feel so good that I actually made something. Try to build a project that you would be interested in and start small, then improve it.
To teach people to code in this way, I started https://enlight.ml that hosts a bunch of "random" projects. As I type this, I'm also working on my next project (https://shamdasani.org/playground) which is my version of codepen/jsfiddle.
I am by no means a professional programmer, but I am gradually learning through building. Hopefully, you'll learn to do the same.