As Dehvina said, the ads to provide the revenue needed to keep the servers up and running. There could even be a chance that they help to keep the website up too!
As for what gets advertised - often times it depends on what people search/do on their computer. I often times get advertisements for iRobot Kitty Litter Robots since I have done a lot of googling of those (I have a cat and she is a bit stinky!). If you play Roblox, that could be the reason on why you get ads for free robux and things like that. It is all done through Google AdSense where it takes your interests and gives you ads based on those so you're more likely to click on them! You can actually disable the "targeted ads" if you go into your browser settings, but who knows what you'd get then!