Let $(X,d)$ be a metric space, $K \subset X$ a nonempty compact subset and $d(x,K) = \inf\{d(x,y):y \in K\}$. Show that there is a $y \in K$ such that $d(x,K) = d(x,y)$.
I have showed that the function $f_{K}(x) = d(x,K), \forall x \in X$ is continuous in $X$.
Now I need to prove that there is a $y \in K$ such that $d(x,K) = d(x,y)$. I found the following argument:
"Since $K$ is a compact set and $d_{K}(x) = d(x,K)$ is continuous, we have due to Weirstrass' theorem that $f$ admits maximum and minimum points. So we have a point $y \in K$ such that $f_{K}(x) = d(x,K) = d(x,y)$".
But to me, the above statement is wrong because $x$, although fixed, is in $X$.
Could someone explain it to me? Because all solutions that I found use this argument.