i) Chlorine atom has 7 electrons in its outermost shell. Its valency is 7. But it is easier for chlorine to gain one electron instead of losing seven electrons. Hence its valency is determined by subtracting seven electrons from the octet and this gives us a valency of one for chlorine.
ii) Sulphur atom has 6 electrons in its outermost shell. But it is easier for sulphur to gain two electrons instead of losing 6 electrons. Hence its valency is determined by subtracting 6 electrons from the octet and this gives us a valency of sulphur is two.
iii) Outermost orbit of Magnesium has 2 electrons, hence it has valency two.