An Asteroid named “2024 YR4” seems to be set to hit the moon on a fine December day in 2032
CAN IT HIT EARTH?

The asteroid was discovered two days after it had already passed its closest point to earth, and it wasn’t detected earlier because it was approaching the earth from the side which isn’t illuminated by the sun.
HOW DO WE CALCULATE ITS TRAJECTORY?

As soon as an asteroid comes into view, we will observe its positions over time. In fact, even if we do not account for the great speeds attained by objects in space, we can still predict the position of any object in the solar system to a good enough degree of accuracy. Consider an object that is 5 million kilometres away from the earth. Such an object is around 10 times further away from the earth than the moon is, and the moon is so far away from Earth that you could fit all the planets of the solar system in the gap between them, and you’d still have ample of space remaining.
WHAT CAN WE DO TO PREVENT AN ASTEROID FROM POTENTIALLY HITTING EARTH?

If such an asteroid was observed, we’d need a timeframe of at least 2 years to do anything. Anything less than that, and we’ll have to roll a dice. After that, we need to deflect its path. For this, even a small projectile can do wonders. We’d have to send a probe in space that would have to collide with the asteroid. Though this will cause quite a small change in its speed, it most probably will be enough, because space itself is quite empty, as illustrated by my earlier argument.