TITLE: Prove that [0,1] is connected.
QUESTION [6 upvotes]: I wrote a proof, and I just wanted to verify if it is correct.
Proof : Suppose not. Then, $[0,1] = U\cup V$ for $U$ and $V$ open in $[0,1]$ such that $U\cap V = \emptyset$. Let $0\in U$. Consider  $s= sup\{t \mid [0,t] \subset U\}$. Clearly, $s\in[0,1]$.
If $s\in U$, then since $U$ is open, $\exists \epsilon >0$ such that $B(s;\epsilon) \subset U$ . But then $s+\epsilon \in U$ , and $s+\epsilon > s$, contradicting the definition of $s$. So, $s \notin U$.
Then, $s\in V$. But again, since $V$ is open, $\exists \epsilon >0$  such that $B(s;\epsilon)\subset V$. But, since $s$ is the least upper bound of $U$, for this $\epsilon$, $\exists s_{1} \in U$ such that $s_{1} \in B(s;\epsilon)$. Then, $s_{1} \in U\cap V$, which contradicts the fact that $U$ and $V$ are disjoint.
So, our assumption is wrong and $[0,1]$ is connected.

REPLY [3 votes]: Theorem
A topological space $X$ is connected iff every continuous function $f: X \to\{±1\}$ is a constant function.
Proof
Let $X$ be a connected space and  $f: X \to \{±1\}$ a continuous function. We want to show that $f$ is a constant function. If $f$ is non-constant, then it is onto. Let $A = f^{-1}(1)$ and $B = f^{-1}(-1)$. Then $A$ and $B$ are disjoint non-empty subsets of $X$ such that $A$ and $B$ are both open and closed subsets of $X$ and $X = A \cup B$. (Why?) This is a contradiction. Therefore $f$ is constant.
Conversely, let us assume that $X$ is not connected. Therefore there exist two disjoint proper non-empty subsets $A$ and $B$ in $X$ such that $A$ and $B$ are both open and closed in $X$ and $X = A \cup B$. Now we define a map $f: X \to \{±1\}$ as
$$f(x) =  \begin{cases} 1,& x\in A\\-1, & x \in B.\end{cases}$$
Then $f: X \to\{±1\}$ is a continuous non-constant function. (Why?) This completes the proof.
Now I am giving you a shorter proof of your problem.
Suppose $j$ is any interval
if  $f: J \to\{±1\}$ is an onto continuous function, then there exist
$x,y\in J$ such that $f(x) = -1$ and $f (y) = 1$. By the intermediate value theorem, there exists $z$ between $x$ and $y$ such that $f(z) = 0$, a contradiction to our assumption that $f$ takes only the values $\pm 1$. Hence no such $f$ exists and hence $J$ is connected. It follows that any interval is connected.