As with any complex skill, it takes time to learn. Early on your time will involve much head scratching, anguish and also looking for that solution that is just beyond your grasp but you know it is there.
Do not be afraid to make mistakes or throw bad code away and start again using a different technique.
Programming early on is a journey into learning a new way to make your mind think. Enjoy the process.
Also... This is the BIG one, I have met many developers that I call cut a paste programmers. They find an example, copy it then try and make it work. If you do look at sample code, do not just copy it. Pull it apart and try to understand what it does and how it does it.
:)
I completely agree with all of this, but especially the last part about copy and paste.