Defining a continuous function from a closed set

Let $F\subseteq \mathbb{R}$ be a nonempty closed set and define $g(x) = inf\{\lvert x-a \rvert : a \in F\}$. Show that $g$ is continuous on all of $\mathbb{R}$ and $g(x) \neq 0$ for all $x \notin F$.

I wasn't sure how to start this problem. Any help would be appreciated.


If $g(x)=0$, then, there exists a sequence $\{x_n\}$ in $F$ such that $|x-x_n|\to0$, so, $x_n\to x$. As $F$ is closed, this implies $x\in F$.

Let $x,y\in \mathbb{R}$,(or $\mathbb{R}^n$, or even any other metric space in general), then, $$g(x)=inf\{|x-a|:a\in F\}\le inf\{|x-y|+|y-a|:a\in F\}=|x-y|+g(y)$$ By the analogous inequaility, $|g(x)-g(y)|\le|x-y|$. So, $|g(x)-g(y)|\to0$ as $|x-y|\to0$. Thus, $g$ is continuous.