How does a virus mutate?

A virus is made up of DNA or RNA then enters your cell, where it can make copies of itself that go off and infect other cells. If your immune system doesn't fight it off, an error may occur causing the virus to mutate.