Here's what I'm trying to prove:
let $K \subseteq \mathbb{R}^n$ be a compact nonempty set and let $f: K \to \mathbb{R}$ be a continuous function. Then:
$$\exists a,b \in K: \forall x \in K: f(a) \leq f(x) \leq f(b)$$
Proof Attempt:
We will just prove the existence of $b$ as a similar argument will apply for the existence of $a$. Suppose, for a contradiction, that:
$$\forall b \in K: \exists x \in K: f(x) > f(b)$$
Define a sequence $(x^{(k)})_{k \in \mathbb{N}}$ as follows:
Since $K \neq \varnothing$, take $x^{(1)}$ to be any element in $K$.
Once $x^{(k)}$ has been defined, define $x^{(k+1)}$ by picking the element of $K$ such that $f(x^{(k+1)}) > f(x^{(k)})$. We know that this exists by assumption.
Since $K$ is compact, the sequence above has a convergent subsequence $(x^{(k_m)})_{m \in \mathbb{N}}$ with limit $x$. However, by definition, the sequence $(f(x^{(k_m)}))_{m \in \mathbb{N}}$ cannot converge and this is impossible because $f$ is continuous and must map convergent sequences to convergent sequences. Hence, the desired $b$ must exist. $\Box$
Does the argument above work? If it doesn't, then why? How can I fix it?
No, it is not correct. You assert (without proof) that “the sequence $\left(f\left(x^{(k_m)}\right)\right)_{m \in \mathbb{N}}$ cannot converge”. That is not true. Suppose, for instance, that $K=[0,1]$ (with its usual topology), that $f\colon K\longrightarrow\Bbb R$ is defined by $f(x)=x$ and that $x^{(n)}=1-\frac1{n+1}$. Then the sequence $\left(x^{(n)}\right)_{n\in\Bbb N}$ converges, and so does the sequence $\left(f\bigl(x^{(n)}\bigr)\right)_{n\in\Bbb N}$.