Two words you often hear in anime are Yatta! and Yokatta. They both express positive feelings, but the words are in fact unrelated and have different meanings.
Yatta is the past tense of the word yaru, to do. So when you hear someone shout Yatta! its primary meaning is “We did it!” or “I did it!”
So whether you hit the jackpot on a fruit machine or your team defeats the universe-eating monster, you are entitled to shout Yatta!
However, the meaning has extended from the literal sense of the word. For example, when I was in Japan and my host mother announced that she was making hotcakes, my little host sisters shouted Yatta!
In this case it wasn’t because they had done anything or even because their mother had (the hotcakes weren’t made yet) but because the word can extend beyond its literal meaning to a general cry of triumph or delight.
Yokatta is the past tense of ii, which means good. Ii is one of the very few irregular words in Japanese. The older form of ii is yoi (which is still often used), and the only irregularity is that whenever ii is conjugated in any way it reverts to being yoi. So the past tense of ii isn’t ikatta but yokatta.
So the meaning of yokatta is clear enough. It means “it was good”. Like yatta, it is often used for things that we don’t necessarily consider to be “past” in English. But when you think about it, the Japanese is logical. Something has to have already happened before we can know whether it was good or not.
Yokatta can be used in many different situations to express relief or happiness at the way things have turned out.
A very common expression in anime is
buji de yokatta
Buji means literally “without incident” but usually has the sense of having arrived somewhere or done something safely or unhurt.
So buji de yokatta means “it was good that you are unhurt”. That puts the past tense in a slightly different place from where English would put it but the sense is the same as “I’m glad you weren’t hurt”.
Yokatta can express happiness in getting a present, passing an exam, or just about anything, but always the root sense is the same: “The way things turned out is good”.
As you have probably already realized, the reason the words look somewhat similar is that they both use the plain past ending -atta.
So, to put it all in a nutshell, when you hand your perfect test result to your mother, you say Yatta! and she says Yokatta.