Here's why the Moon stays orbiting Earth despite the Sun's influence:
* The Moon is closer to Earth: The force of gravity weakens with distance. While the Sun's gravitational pull is stronger overall, the Moon is much closer to Earth, making Earth's gravitational pull stronger on the Moon.
* Orbital mechanics: The Moon is in orbit around Earth because of its velocity and the balance between Earth's gravity and the Moon's inertia (its tendency to move in a straight line). This delicate balance keeps the Moon from flying off into space or falling into Earth.
Think of it like a ball on a string. You swing the ball around in a circle. The string acts like Earth's gravity, keeping the ball from flying off. The Sun's gravity is like a slight tug on the string, but not strong enough to pull the ball away completely.
The Moon's orbit around Earth is actually slightly affected by the Sun's gravity. This causes the Moon's orbit to be slightly elliptical, and it's also why we have lunar phases.