Here's the solution provided:

I don't understand how they got that answer! This is my own attempt:

Since $\displaystyle f$ is a piece-wise function I divided the interval to two and calculated the inner product like this:

$\displaystyle \left\langle f, sin(x) \right\rangle = \int^{0}_{-\pi} -sin(x)+\int^{\pi}_{0} sin(x)=$$\displaystyle cos(0)-cos(\pi)-(-cos(\pi)-cos(0))=-2$

So, why is my method and my answer wrong? And could anyone please explain the method used in the model answers?