We need the codomain to equal the image.

You can see that the limit of g(x) as x -> infinity is 2, and the limit of g(x) as x -> -infinity is also 2. In particular, g(x) never takes on the value of 2, and the image of g is R \ {2}.

So set that as the codomain and you're good to go.