I am trying to find a function such that $\lim_{x \to a}|f(x)| = |L|$, but $\lim_{x \to a}f(x) \ne L$. I came up with this:
$f(x) = 1$ if $x$ is a positive or negative even number
$f(x) = -1$ otherwise.
Then, $|f(x)| = 1 \, \forall x$. Put $a=0$. Then, $\lim_{x \to 0}|f(x)| =1$ , but $\lim_{x \to 0}|f(x)| =-1$ and we are done. I am not sure if this example is correct. If we look at the contrapositive of the statement:
$\lim_{x \to a}|f(x)| = |L|$, but $\lim_{x \to a}f(x) \ne L$
the example fails because $\lim_{x \to 0} f(x) = -1$ (which implies $L=-1$) and $\lim_{x \to 0} |f(x)| = 1 = |L|$. Is this example correct?
No, your solution is not completely correct, but you are on the right track. Try $f(x)=x/|x|$ and $a=0$ instead.
Actually, even simpler would be $f(x)=-1$, $L=1$, any $a$. Are you sure the problem is stated correctly? Is $L$ given?