Explanation:
It is true that when a neutral atom tends to lose an electron then it forms a positively charged ion called cation. And, when a neutral atom tends to gain an electron then it forms a negatively charged ion called anion.
For example, the atomic mass of magnesium is 12 and its electronic configuration is [tex]1s^{2}2s^{2}2p^{6}3s^{2}[/tex].
So, in order to attain noble gas configuration it will lose its 2 valence electrons. Therefore, it will form [tex]Mg^{2+}[/tex] ion.
And, atomic number of chlorine is 17 and its electronic configuration is [tex]1s^{2}2s^{2}2p^{6}3s^{2}3p^{5}[/tex]. To attain noble gas configuration it will readily accept an electron from a donor atom.
Hence, it will form [tex]Cl^{-}[/tex] ion.