This is a fantastic question!
Overview: you will need to convert grams to moles and use stoichiometry to solve for this problem.
STEP 1: Check to see if the equation is stoichiometrically balanced.
Mg + 2HCl --> MgCl2 + H2 (yes! it is balanced)
STEP 2: convert the 5 grams to moles of HCl
- add up the molar masses of H and Cl = 1.001g + 35.45g= 36.45g per mole of HCl
- divide the number of grams given by the grams per mole of HCl
5g/36.45 g per mole = 0.14 moles of HCl
3) now, using stoichiometry, understand that for every 2 moles of HCl, you need 1 mole of Mg. This means that you must use 1/2 the moles of HCl for Mg.
0.14moles / 2 = 0.07 moles of Mg
Hope this helps!