It has been some time since I studied Fourier analysis, but here is my take. Let $f$ be some odd function. In particular this means that
$$ \int_{-\pi}^{\pi} f(x) \cos nx \,\mathrm{d}x
= 0 $$
You can prove this yourself by splitting the integral in two and using that for any odd function we have $f(–x) = –f(x)$. Now all we have to do is find some odd function such that the integral converges.
$$ \int_{-\pi}^{\pi} f(x) \sin nx \,\mathrm{d}x
= 0
$$
You can nearly choose whatever you want here. Let for instance $f$ be a bounded and continuous function for $x \in [-\pi, \pi]$. This ensures that the integral converges.
$$K = \int_{-\pi}^{\pi} f(x) \sin nx \,\mathrm{d}x \leq \int_{-\pi}^{\pi} |f(x)| \cdot |\sin nx| \,\mathrm{d}x
\leq \int_{-\pi}^{\pi} |f(x)| \,\mathrm{d}x$$
Note, we do not have to pick $f$ to be continuous all we need to do is pick $f$ such that the integral above converges. However, it is merely convenient to just let $f$ be bounded and continuous as it makes life easy... As the integral converges, we know that the result is some value $K$. We can now achieve our goal by selecting our final function
$$\overset{\sim}{f}(x) = \frac{1}{K} \frac{(-1)^n}{\sqrt{n}}f(x)$$
where $\overset{\sim}{f}$ is an bounded, odd and continuous function for $x \in [-\pi, \pi]$.
This function satisfies the two restrictions
$$ \displaystyle
\int_{-\pi}^{\pi} \overset{\sim}{f}(x) \sin nx \,\mathrm{d}x
= \frac{(-1)^n}{\sqrt{n}}
\qquad \text{and} \qquad
\int_{-\pi}^{\pi} \overset{\sim}{f}(x) \sin nx \,\mathrm{d}x = 0
$$
Example: Take $g$ to be defined as $x$. Then
$$
K = \int_{-\pi}^{\pi} g(x) \sin nx \,\mathrm{d}x = \int_{-\pi}^{\pi} x \sin nx = \frac{2 \sin(\pi n) - 2\pi n \cos(\pi n)}{n^2}
$$
So let
$$f(x) = \frac{n^2}{2 \sin(\pi n) - 2\pi n \cos(\pi n)} \frac{(-1)^n}{\sqrt{n}} x$$
Then
$$ \displaystyle
\int_{-\pi}^{\pi} \overset{\sim}{f}(x) \sin nx \,\mathrm{d}x
= \frac{(-1)^n}{\sqrt{n}}
\qquad \text{and} \qquad
\int_{-\pi}^{\pi} \overset{\sim}{f}(x) \sin nx \,\mathrm{d}x = 0
$$