Answer:
Since magnesium has two extra electrons it looks around for elements which could use them. In this case, magnesium bonds with two chlorine atoms which each need one electron. With the additional electron, chlorine has a filled shell and magnesium loses two electrons.