Atoms gain or lose electrons in order to achieve a noble gas configuration (an octet). The formula for the ionic compound zinc chloride is #"ZnCl"_2#. When forming an ion, a zinc atom loses its two valence electrons, becoming a #"Zn"^"2+"# ion. The chlorine atom has seven valence electrons, and will gain one valence electron to form a chloride ion, #"Cl"^"1-"#. Ionic compounds are neutral, which means that the sum of the positive charges and the negative charges must equal zero. Therefore, two chloride ions, #"Cl"^"1-"# must bond with one zinc ion, #"Zn"^"2+"#. The sum of the positive two charge on the zinc and the negative one charge on the two chloride ions equals zero. The ionic bond is formed by the electrostatic attraction between the oppositely charged ions.
#"Zn"# + #"Cl"_2# #rarr# #"Zn"^"2+"# + #"Cl"^"1-"# + #"Cl"^"1-"# #rarr# #"ZnCl"_2#