Let $f : I \to \mathbb R$ be continuous. For any compact interval $J \subseteq f(I), \exists$ a compact interval $K \subseteq I$ with $f(K)=J.$ 
Let $f \colon I \to \mathbb R$ be continuous where $I$ is an interval. For any compact interval $J \subseteq f(I)$ there exists a compact interval $K \subseteq I$ such that $f(K)=J.$

My attempt:
Let $J=[f(x),f(y)]$ wehre $x,y \in I.$ Without loss of generality $x<y.$ Let $p=f(x), q=f(y).$
Let $$A=f^{-1}\{p\}\cap [x,y]$$ Then $A$ is closed and bounded, hence compact. Therefore, $r=\sup A \in A.$ Thus, $f(r)=f(x).$
Similarly, let $$B=f^{-1}\{q\}\cap [x,y]$$ Then $s=\inf B \in B$. Thus, $f(s)=f(y).$
Now I want to show that $f([r,s])=J.$ I understand intuitively and geometrically that if there is a point $w \in [r,s]$ such that $f(w)<f(x)$ Then we'll get a point in $(w,s)$ such that $f(w)=f(p).$ This will contradict the definition of $r.$ However, I'm not able to make this precise.

Is there a rigorous argument to show $f([r,s])=J?$


WLOG $p\leq q.$ (Otherwise  study the function $g(t)=-f(t)$...). We have $$f([r,s])\supset [f(r),f(s)]=[p,q]$$ by  the IVP, because $f$ is continuous. 
If $t\in (r,s)$ and $f(t)<p\leq q=f(s)$ then by the IVP there exists $t'\in (t,s)$ with $f(t')=p,$ contrary to the def'n of $r.$ 
If $t\in (r,s)$ and $f(t)>q\geq p=f(r)$ then by  the IVP there exists $t''\in (r,t)$ with $f(t'')=q$ contrary to the def'n of $s.$ 
So $f([r,s])\subset [p,q].$
