Calculating the number of neutrons in a sample
The formula

$$\text{amount of substance} = \frac{\text{mass}}{\text{molar mass}}$$

tells you that you have 1/12 moles of magnesium, since you are taking the mass of magnesium (2 g) and dividing by the molecular mass of magnesium (24 g/mol). However, the question is not asking about the number of moles of magnesium.

Each magnesium atom has 24 - 12 = 12 neutrons. Consequently, 1/12 moles of magnesium has (1/12)(12) = 1 mole of neutrons.