Does my computer have a virus and if so, what should I do?

A month ago, I clicked on this ad on my mac about a free iPhone which now I realize is a very bad idea. I haven't lost anything but its really annoying because ever since then when I've gone on Safari, ads pop up randomly in a new tab. I've also gotten an enormous amount of ads and videos on the side where they wouldn't usually be. The ads are usually dating sites or "an important security question" or clean my mac. I'm pretty sure that I have a Virus and its getting really annoying. Does anyone know how to get rid of it?

Sounds like adware or spyware.

It's adware not a virus. Most of the malware on MACs these days are browser infections. In the form of an extension or addon. Some of these bad extensions are hidden… So if you can't see anything bad, reset the browser
to reset safari http://support.apple.com/...kb/ph17186

there are also a few pieces of malware that are not as easy to remove. Please refer to this site/page
http://www.thesafemac.com/arg/

also consider have at least one other browser. Preferably firefox. In which you could install the addons called adblock plus and adblock edge