To solve a ratio you must first figure out how many parts of the ratio you have. In this case the ratio is 3:7 so we add them and get 10 parts (3+7)
Now that we know the total parts of the ratio we can figure out how much 1 part of the ratio is worth by dividing the total number (40) by the total parts of the ratio (10) 40/10 = 4
Now that we know each part of the ratio equals 4 we multiply each side of the ratio by 4
3 * 4 = 12 Niamh got 12 pencils
7 * 4 = 28 Jack got 28 pencils