This question is based on the concept of limiting reagent. In this concept, we take the balanced equation of the reaction, as follows :-
Mg + O2 --> 2MgO......................(1)
Here, 1 Mole of Mg reacts with 2 Mole of Oxygen to form 2 Moles of MgO
so, according to the question, there is 8 grams of Mg and O
=> Moles of Mg is 8/24 = 1/3 moles.
=> Moles of Oxygen = 8/32 = 1/4 moles.
This means Oxygen is limited in comparision with Mg
Now, by equation (1)
we know that 2 moles of oxygen form 2 moles of MgO
=> => 1 Mole of Oxygen [I am not talking of Oxygen gas] will form 1 mole of MgO
=> 1/4 mole of oxygen atoms will form 1/4 mole of MgO
1 Mole of MgO weighs 56 grams
=> 1/4 mole of MgO weighs 56/4= 14 grams,
I did the question quickly, so see if there's error, and also, you need to know what is limiting factor. It is the compound/element, which is limited in the reaction, and thus limits the reaction. For example in the above reaction, Mg was in more amount than Oxygen [1/3 > 1/4] so, O is the limiting factor instead of Mg.