What was the reason for John, Mark, Luke, and Matthew writing their gospels? Why did it take 35-40 years after the resurrection and ascension of Jesus to begin to write the gospels or the rest of the New Testament?
As for the purpose of the gospel accounts, see "The Four Gospels."
As to the time, please understand that Gospels do not mention when they were written. It is modern-day skeptics, claiming to be Bible scholars, who assign dates to the gospels that are often long after the actual events. But these dates come from their lack of belief in the Bible.
For instance, the Gospels mention the destruction of Jerusalem in detail. The modern-day skeptic can't fathom Jesus being able to predict the events so accurately in advance, so they assume that Jesus' followers wrote about the events just before or just after the events and then attributed their statements to Jesus. Because, from a skeptic's viewpoint, no one is 100% accurate except through hindsight.
Then, too, skeptics can't imagine Jesus being portrayed accurately, so they assume that legends had to have developed first and then the legends were written down. Such legends would take years to develop, so they assume the writings were much later.
But there are numerous flaws in the assumptions. We know that Paul wrote his letters as he traveled around the world. For example, the first letter to the Corinthians contains a quote from the Last Supper. If you compare it to the gospel accounts, you will realize that Paul is quoting from Luke's account of the events. That would imply that Luke was written before I Corinthians, which some guess to be written about A.D. 54.
The book of Acts ends with Paul awaiting his first trial in Rome. But Paul mentions that he was released after his trial and implies that he spent some time teaching in Gaul (Spain) as well as traveling to other areas before his second trial that ended with his death. That means Acts was written about A.D. 62.
We don't know exactly when the four gospels were written, but it wasn't as long as 35 to 40 years after Jesus' death.