Ender remains hopeful during his time in Salamander Army because he makes friends with Petra. She teaches him how to become a better marksman. He also keeps his hopes up by practicing during his play time with other "launchies" in the battle room and he learns by observing what other armies do correctly and incorrectly. He also has hope because Bonzo is trying to trade him away to another army. Ender is convinced that he will be a good soldier eventually. He also sees that he will be superior to the other soldiers in Salamander Army.
Most importantly, Ender remebers that Alai had told him there was always at least one person worth knowing in any army To which Ender would be assigned.
"When Ender gets assigned to Salamander Army, Alai reveals his true friendship in a hug and a whispered "Salaam." "Whatever it meant to Alai, Ender knew that it was sacred; that he had uncovered himself for Ender, as Ender's mother had done, when he was very young." Alai's voice is the first Ender hears when he is finally allowed to work with others at Command School."