Why did the Israelites wander the desert for 40 years?


The Lord said to Moses, “Send some men to explore the land of Canaan, which I am giving to the Israelites. From each ancestral tribe send one of its leaders.” Numbers 13:1-2
            God sent twelve spies, one from each tribe, during the time of Moses into the Promised Land to come back with a report.  They did and returned forty days later (Numbers 13:25).
            Their report was good (the land was fertile and the grapes were huge) and bad (the people were giants).  This caused fear and doubt.  God was mad that the people didn’t trust him to defeat giants.  So He sentenced an entire generation, those twenty and older, to death in the wilderness, not allowing them to enter the Promised Land for the amount of time it would take for that generation to die off—forty years.
For forty years—one year for each of the forty days you explored the land—you will suffer for your sins and know what it is like to have me against you.” Numbers 14:23
            After the 40 years, only three from that generation survived – Moses, Joshua and Caleb, who all had faith in God.