I am trying to find the Fourier series for $f(x) = |x|$ on the interval $(-\pi, \pi]$ extended periodically with period $2\pi$.
I know that $a_0 = \displaystyle\frac{\pi}{2}$. I am having trouble with $a_n$.
I know the formula for $a_n = \displaystyle\frac{1}{\pi} \int_{-\pi}^{\pi} f(t)$ cos$(nt)$ $dt$
So plugging in: $a_n = \displaystyle\frac{1}{\pi} \int_{-\pi}^{\pi} |t|$ cos $(nt)$ $dt$
I am having trouble with this integral. I know I have to use integration by parts which I know how to do. I am just stuck integrating $|t|$.

Integrate it piecewise. Since $|t|$ is $(-t)$ on $[-\pi,0]$ and is $t$ on $[0,\pi]$, you have $$\int_{-\pi}^{\pi}|t|\cos nt\; dt = \int_{-\pi}^{0}(-t)\cos nt\; dt + \int_{0}^{\pi}t\cos nt\; dt$$
Or, since the integrand is even, you could just say
$$\int_{-\pi}^{\pi}|t|\cos nt\; dt = 2\int_{0}^{\pi}t\cos nt\; dt$$
They are the same thing, if you simplify the first one a little bit.