In 1777, there was nothing certain about an American victory against the British.
We might have General Howe to thank. Had he pursued the Continental Army, Howe might have crushed the revolution in 1777. Instead, Howe thought he could cut the head off the revolution by taking the capital. Being made of men and not buildings, the capital moved to York during the Philadelphia occupation. Failing that, Howe tried to win the hearts and minds of the Philadelphia elite with parties.
Even though Washington’s Army did not have to contend with the British at Valley Forge, they did have supply shortages and disease that took men just the same. The turnaround came with the help of a Prussian officer, Friedrich Wilhelm von Steuben who rebuilt the army into a world class force while literally writing the the book on the US Army to come. Even still, the war went on until 1783.