In order to find the percentage of an element within a compound, we need to have the mass for this element and also the mass of the whole compound, and the masses are:
H = 1.008 g/mol or amu
and we have 3 H in the compound, therefore = 3.024 g/mol or amu
NH3 = 17.031 g/mol
Now we know that 17.031 is the total mass, so we will call it 100%
17.031 g/mol = 100%
3.024 g/mol = x %
x = 17.75% of H in NH3