Hello, Jules.
We will set up proportions to figure it out:
5 green marbles : 8 red marbles which gives you the ratio 5/8
X green marbles : 40 red marbles which gives you the ratio X/40
Now you have to set those two ratios equal to each other and solve for X, the number of green marbles:
If a bag has 40 red marbles, it contains 25 green marbles.