I am trying to find the Fourier sine series of the following function:
$$ f\left(x\right)= \begin{cases} 1&x<L/2,\\ 0&x>L/2.\tag{1} \end{cases} $$
Let $L=1$. Then, this is what $\left(1\right)$ looks like:

I know that to find the Fourier sine series of $\left(1\right)$, I first need to find its odd extension $f_o$:
$$ f_o\left(x\right)= \begin{cases} 1&0<x<L/2,\\ 0&L/2<x<L\text{ & }-L<x<L/2,\\ -1&-L/2<x<0.\tag{2} \end{cases} $$
Again, letting $L=1$, this is what $\left(2\right)$ looks like:

Finally, the Fourier sines series of a piecewise smooth, odd function $f\left(x\right)$ is given by
$$ f\left(x\right)\sim\sum_{n=1}^{\infty}B_n\sin\frac{n\pi x}{L}, $$
where
$$ B_n=\frac{2}{L}\int_{0}^{L}f\left(x\right)\sin\frac{n\pi x}{L}.\tag{3} $$
Now, I am having a really hard time trying to find $\left(3\right)$ because, for the case where $0<x<L/2$, I get
$$ \frac{2}{n\pi}\left(1-\cos\left(n\pi\right)\right), $$
and for the case where $-L/2<x<0$, I get
$$ \frac{2}{n\pi}\left(\cos\left(n\pi\right)-1\right). $$
So, it is piecewise defined, but my book only gives one solution, that is,
$$ \frac{2}{n\pi}\left(1-\cos\frac{n\pi}{2}\right). $$
What am I missing!?