If a function $f$ is continuous on $[a,b]$, then it attains its maximum and minimum values on $[a,b]$.
We prove the case that $f$ attains its maximum value on $[a,b]$. The proof that $f$ attains its minimum on the same interval is argued similarly.
Since $f$ is continuous on $[a,b]$, we know it must be bounded on $[a,b]$ by the Boundedness Theorem.
Suppose the least upper bound for $f$ is $M$.
If there is some $c$ in $[a,b]$ where $f(c) = M$ there is nothing more to show -- $f$ attains its maximum on $[a,b]$.
Suppose there is no such $c$. Then $f(x) \lt M$ for all $x$ in $[a,b]$.
Define a new function $g$ by $\displaystyle{g(x) = \frac{1}{M-f(x)}}$.
Note that $g(x) \gt 0$ for every $x$ in $[a,b]$ and $g$ is continuous on $[a,b]$, and thus also bounded on this interval (again by the Boundedness theorem).
Given that $g$ is bounded on $[a,b]$, there must exist some $K \gt 0$ such that $g(x) \le K$ for every $x$ in $[a,b]$.
Consequently,
$$\frac{1}{M-f(x)} \le K$$which implies (upon multiplication of both sides by the positive $M-f(x)$, followed by a division on both sides by $K$) that for every $x$ in $[a,b]$:
$$f(x) \le M - \frac{1}{k}$$This is impossible, however, as it contradicts the assumption that $M$ was the least upper bound!
That leaves as the only possibility that there is some $c$ in $[a,b]$ where $f(c) = M$. That is to say, $f$ attains its maximum on $[a,b]$.