Since we already have the counts of the number of moles of each element in 1 mole of ammonium nitrate (which are 2 mol N, 4 mol H, 3 mol O), we multiply each of these by the molar masses:
N has a molar mass of 14.0 g/mol, so multiplying by 2 mol N gives 28.0 g N
H has a molar mass of 1.0 g/mol, so multiplying by 4 mol H gives 4.0 g H
O has a molar mass of 16.0 g/mol, so multiplying by 3 mol O gives 48.0 g O
So there are 28.0 g N, 4.0 g H, and 48.0 g O. (The total mass would be 80.0 g ammonium nitrate.)