> read the code and try to understand it and then just copy it.
That's not learning by doing that's learning by copying. :) I don't think learning by copying works which is why your approach is flawed.
Next time try this instead. Google it, find some code, read it and try to understand it like you do now. Then don't copy it. Instead open it in a text editor window and in another you rewrite the code. If you don't know how to rewrite it, just do it character by character.
Now you might say "that's just a slower form of copy-paste!" but no, it is not. After a few times trying this, you will see why it isn't. It is the method I use and it works for me.