All those things happened to the Israel people to show us that God is not happy with people that do bad things. Those things happened so that we will not want to do bad things, like they did.