(a)    hydrogen has 1 electron & chlorine has 7 electrons in its valence shell 
hydrogen removes 1 electron & gets stabilised whereas chlorine accepts the ejected electron from hydrogen atom & achieves the octet to get stabilised in hydrogen chloride molecule . as chlorine accepts 1 electron so valency of it is 1
 (b)   the metals which shows more than one valency are generally transition metals . the  transition metals have incompletely filled d orbitals . so they exhibit variable valencies