there are lots of different purposes for these shots:
you can use a topspin to add security to your game because a topspin stroke flies higher over the net, thus less risky for you
or a long topspin that bounces near the baseline on a surface which adapts the spin well is good to try forcing your opponent further back
you can play good and aggressive short angles with short topspin shots
a slice is mostly used if you are under pressure and can't execute an offensive shots anymore good enough due to the lack of time
or a slice is a good weapon to make the game slower to allow you recovering your position on the court
often some opponents find it harder to accelerate a slice shot than if you give them power
both shots can be important part of your game to vary and change the rhythm and pace of the game to make you less calculable what you're doing next
and if you are a beginner you must pay attention that you are using the right grips, a forehand topspin with a (or an almost) backhand grip is not working well

try to search a bit in the internet if you're not familiar with the different grips yet, you might find some instructions and pictures