Just an FYI...but this doesn't always happen. The electors of each state can decide to ignore the popular vote (of their state) and vote for whoever they want.
It happened in the 2000 presidential election. Al Gore won the popular vote, Bush won the electoral vote.