The Avengers was always going to be a difficult movie to write. The screenwriter needed to please the fanboys and girls who have read the comic books, while also exciting non-fans who might not be interested in seeing a superhero movie.
But it turns out that the geeky Joss Whedon was the perfect choice to write this film, along with the help of Zak Penn (X2). As Kofi Outlaw noted in his review, "Whedon is in tune with every single one of the superheroes (and villains) in Marvel’s stables, and knows how to arrange those personalities into a well-balanced ensemble like a perfectly assembled puzzle."
Whedon's love for both the characters and the story was evident in The Avengers, and that affection helped bring these characters to life on the big screen.