Let $G$ be a group of order 3, $G= <g>$ and let $H$ be a group with an element h of order 4. Let $f: G --> H$, where $f(g^i)= h^i$. Then f is not an homomorphism because $f(g^3)= h^3$ but $g^3= 1$ and $h^3 \neq 1$. However $f(g^ig^j)= f(g^{i+j})= h^{i+j}= h^i h^j= f(g^i)f(g^j)$. Where is the mistake?

In particular $f(gg^2)=f(g^3)=h^3=hh^2=f(g)f(g^2)$ and again the contradiction.