When you find yourself stuck or find that you've messed things up, don't get discouraged. Having to untangle and clean up the mess gives you a much better understanding of the way things work than if you never make a mistake. As frustrating as it might be, the challenge of fixing mistakes is a great opportunity to learn.
Sometimes when you get really confused, one option is to start from scratch. You'll usually realize where you went wrong and you'll have a better understanding of the process.
When you are learning a new technology, whether you are learning to write your first programming language, or just the latest framework, you go through this uncomfortable phase where you know that the code you are looking at is doing this THING but you don't understand HOW exactly it's happening
This is a normal part of the process of learning a new technology, and in fact, it's a critical part of the process.
You see when you encounter a new programming language part of your learning process includes learning to train your eye. The way to train your eye is to read a good deal of code even when you don't totally understand what it's doing.