God wanted to destroy the people for their idolatry, but Moses interceded in their behalf. This was probably a test for Moses. Think about it: God is omniscient (all knowing) and omnipotent (all powerful). He was not caught off guad by Israel’s actions. God wanted to confront Moses and see what he was made of. As a good leader, he interceded for his people.