"Success is not final, failure is not fatal: it is the courage to continue that counts." -Winston Churchill
We all have times like these. Times where things just don't work out the way you want them to. We fail that test, or we can't figure out how to solve that problem. Maybe you're trying something new and you've attempted it three times and still can't do it right. It's all part of the learning process, and just because you can't do it the first time doesn't mean that you shouldn't or can't do it at all. Keep trying.
Our entire life is one big giant lesson. There is no list of directions or big secret that answers all the questions we have. There is no right way to life. There's a never-ending amount of good/better ways and bad/worse ways to do things.
That being said, failure is inevitable. Us as human beings are no where near perfect, and that is okay. We are incapable of doing everything right all the time. Which is why every time we fail we must get back up and try again. Try something thousands of times over until you figure it out or get it right. Never, ever give up. Keep working at it, because imagine the rewarding feeling you'll get when you finally figure it out and how much you learned in the process.
When you fail, it allows you to grow and learn. It benefits you whether you realize that at the time or not. You may not have figured out the right way, but you did figure out all of the wrong ways.
"I have not failed. I've just found 10,000 ways that won't work." -Thomas A. Edison
Bottom line is, you will be okay. Everything will be okay. Just like Churchill said, failure is not fatal. Get back up, keep trying, don't stop now.