$(X,d)$ is metric space. $(X,d)$ is compact if and only if any continuous function on $X$ has a maximum. $(X,d)$ is metric space. $(X,d)$ is compact if and only if any continuous function on $X$ has a maximum.
I dont know whether these functions real valued or not but only real valued functions may make sense, I think.
In that case
$\Rightarrow$ is easy.
About $\Leftarrow $
My 1st attempt:
I thought some special functions that I can use e.g. $$\varphi:X\to \mathbb R\\ \varphi(x)=d(x_0,x)$$ for some fix $x_0\in X$
Since this is a continuous function then it attains its maximum on $X$, that implies $X$ is bounded .
With this motivation I can define $$\psi:X\to \mathbb R \\\psi(x)=d(x,X)=\inf\limits_{a\in X}d(x,a)$$
since it attains its maximum so $X=\overline X$
So I have boundness and closedness but these dont really imply compactness in metric spaces.
My 2nd attempt was:
Considering any sequences in $X$ and using $f(x_{k_n})$ is convergent iff $x_{k_n}$ is convergent. By showing every sequence has convergent subsequence and using continuity of any $f:X\to\mathbb R$.
I am stuck is there hint or answer you can give me?
 A: HINT: Prove the contrapositive: assume that $X$ is not compact, and construct a continuous real-valued function that does not attain a maximum. Perhaps the simplest approach is to show that if $X$ is not compact, it has a countably infinite closed discrete subset $D=\{x_n:n\in\Bbb N\}$. Define $f:D\to\Bbb N:x_n\mapsto n$ and apply the Tietze extension theorem.
Added. It’s more work, but you can actually avoid the Tietze extension theorem. Every subset of $D$ is closed, and $X$ is normal, so we can carry out the following construction. There are open sets $U_0$ and $V_0$ such that $x_0\in U_0$, $D\setminus\{x_0\}\subseteq V_0$, and $\operatorname{cl}U_0\cap\operatorname{cl}V_0=\varnothing$. Suppose that $n\in\Bbb N$, and we already have an open set $V_n$ containing every $x_k$ with $k>n$; then there are open subsets $U_{n+1}$ and $V_{n+1}$ of $V_n$ such that $x_{n+1}\in U_{n+1}$, $x_k\in V_{n+1}$ for each $k>n+1$, and $\operatorname{cl}U_{n+1}\cap\operatorname{cl}V_{n+1}=\varnothing$. In this way we recursively construct open sets $U_n$ with pairwise disjoint closures such that $x_n\in U_n$ for each $n\in\Bbb N$.
Let
$$\mathscr{U}=\left\{X\setminus\bigcup_{n\in\Bbb N}U_n\right\}\cup\{U_n:n\in\Bbb N\}\,;$$
$\mathscr{U}$ is an open cover of $X$. $X$ is a metric space, so it is paracompact, and $\mathscr{U}$ therefore has a locally finite open refinement $\mathscr{R}$. For each $R\in\mathscr{R}$ there is a $U_R\in\mathscr{U}$ such that $R\subseteq U_R$. For each $U\in\mathscr{U}$ let $V_U=\bigcup\{R\in\mathscr{R}:U_R=U\}$, and let $\mathscr{V}=\{V_U:U\in\mathscr{U}\}$. It is not hard to show that $\mathscr{V}$ is locally finite, and it is clearly an open refinement of $\mathscr{U}$, since $V_U\subseteq U$ for each $U\in\mathscr{U}$.
For $n\in\Bbb N$ let $V_n=V_{U_n}$. Note that $U_n$ is the only member of $\mathscr{U}$ containing $x_n$, so $x_n\in V_n$. $X$ is completely regular, so for each $n\in\Bbb N$ there is a continuous function $f_n:X\to[0,1]$ such that $f(x_n)=1$ and $f_n[X\setminus V_n]=\{0\}$. For $x\in X$ let
$$f(x)=\sum_{n\in\Bbb N}nf_n(x)\,;$$
clearly $f$ is a function from $X$ to the non-negative reals, and $f(x_n)=n$ for each $n\in\Bbb N$, so $f$ is unbounded above. It’s also clear that $f\upharpoonright V_n=f_n$ for each $n\in\Bbb N$, so $f$ is continuous at each point of $\bigcup_{n\in\Bbb N}V_n$.
Finally, let $x\in X\setminus\bigcup_{n\in\Bbb N}V_n$; clearly $f(x)=0$. If $x$ has an open nbhd $W$ disjoint from $\bigcup_{n\in\Bbb N}V_n$, then $f[W]=\{0\}$, and $f$ is continuous at $x$. If not, then $x\in\operatorname{cl}\bigcup_{n\in\Bbb N}V_n$. $\mathscr{V}$ is locally finite, so $x$ has an open nbhd $W$ such that $F=\{n\in\Bbb N:W\cap V_n\ne\varnothing\}$ is finite. Then
$$x\in\operatorname{cl}\bigcup_{n\in F}V_n=\bigcup_{n\in F}\operatorname{cl}V_n\,,$$
and the sets $\operatorname{cl}V_n$ are pairwise disjoint, so there is a unique $n(x)\in\Bbb N$ such that $x\in\operatorname{cl}V_{n(x)}$. I’ll leave the very last step to you: use this fact to show that $f$ is continuous at $x$, thereby completing the proof that $f$ is continuous.
