Shit happens. Kudos for admitting it was your fault and not blaming anyone else.
The first line of defense against viruses is not downloading/installing suspicious stuff. Google before you download a program, and don't click on the advertised links, click on the official ones.
It takes a long time to get comfortable with knowing what is and is not suspicious, and even then, we make mistakes. I've been computer-ing as a power user since I was wee, and I've still managed to install some viruses over the years.
Apart from good judgment, keep your programs up to date, keep windows up to date, set up the windows virus / malware scanner (called windows defender) to active (some people turn it off for some reason.) And keep backups.
Also, ignore anyone who tells you that macs and linux are impervious to viruses. They are not. It's just much less common.