Let c be the number of chocolates in the box, and n be the number of boys.
If they have 6 chocolates each there are 12 left in the box, so:
c=6n+12.
If they have 10 chocolates each, there are not enough chocolates in the box, so we would have to add 8 chocolates, so:
c+8=10n, and c=10n-8.
Therefore we can write:
c=6n+12=10n-8.
And we can find n from:
6n+12=10n-8,
20=4n, so 5=n, there are 5 boys (and 42 chocolates).