Isomorphism between direct products

So I have to prove the following that if G and H are Groups then

$G \times H \cong H \times G$

I was thinking about showing the homomorphism:

I would define $f: G \times H \rightarrow G$ by $f(a,b)=(a,b)$

$f(a,b)=(a,b)=...$

I was hoping to type more of my answer, but I am not sure on how to proceed any hints would be helpful.

• The map $f:G\times H \longrightarrow G$ by $f(a,b)=(a,b)$ doesn't make sense because $(a,b)$ is an ordered pair, and elements of $G$ aren't, a priori, ordered pairs. – Chickenmancer Mar 13 '18 at 5:32

That doesn't make sense. What if $a\notin H$?
Hint: Try $f(a,b)=(b,a)$ instead.
• Where $f:G\times H \longrightarrow H\times G.$ – Chickenmancer Mar 13 '18 at 5:33
Okay thanks so I gave it a try: Injective $f(a,b)=f(c,d) \implies (a,b)=(c,d) ?$. $f(a,b)=f(c,d) \implies (b,a)=(d,c) \implies (a,b)=(c,d)$ Injective
Onto: $(f(G \times H) = f((a,b)| a \in G \ and\ b \in H) = ((b,a)|(b,a) \in H \times G) = H \times G$ Hence onto
Homomorphism since $f((a,b),(d,c))=[(b,a),(d,c))=((b,d),(a,c))=((b,a),(d,c))=f(a,b)f(c,d)$