Super smart! We have \(3 \, \mathrm{gm}\) of Hydrogen and \(8 \, \mathrm{gm}\) of Oxygen. To form water, \(3 \, \mathrm{gm}\) of Hydrogen needs \(24 \, \mathrm{gm}\) of Oxygen. But, we have only \(8 \, \mathrm{gm}\) of Oxygen. So, the \(8 \, \mathrm{gm}\) of Oxygen combines with \(1 \, \mathrm{gm}\) of Hydrogen to produce \(9 \, \mathrm{gm}\) of water. We will have \(2 \, \mathrm{gm}\) of Hydrogen left over.
I hope the law of constant proportions is more clear to you now. Just like you need letters in a perfect combination to form a word, you need different atoms in a perfect ratio to form a compound.