Is my proof of this correct?
We will prove the contrapositive, that if $X$ is not compact there exists a continuous real valued function on $X$ that is unbounded. Since $X$ is not compact, there exists a sequence with no convergent subsequence. Consider such a sequence, $a_n$. Because $X$ is a metric space, $X$ is Hausdorff, and the sequence $a_n$ does not have an accumulation point lest it would have a convergent subsequence, so for each $a_n$ we can construct $B_{\epsilon_n}(a_n)$ such that each ball is disjoint. Now define $$f(x) = \begin{cases} 0 & x \not \in B_{\epsilon_n}(a_n)\\ n - n\frac{d(x, a_n)}{\epsilon_n} & x \in B_{\epsilon_n}(a_n)\\ \end{cases}$$ $f(x)$ is unbounded as $f(a_n) \rightarrow \infty$ as $n \rightarrow \infty$. $f(x)$ is also continuous by the pasting lemma as it is continuous on the closure of $\cup_{n=1}^{\infty} B_{\epsilon_n}(a_n)$ and the complement of $\cup_{n=1}^{\infty} B_{\epsilon_n}(a_n)$, which are both closed sets which union to $X$. Therefore $f(x)$ is continuous on $X$. So we have shown that if $X$ is not compact, there exists a continuous real valued function on $X$ that is unbounded, which is the contrapositive of the statement we were to prove.