A function that satisfies the Intermediate Value Theorem and takes each value only finitely many times is continuous. I'm having a confusion over the veracity of the statement that a function that satisfies the Intermediate Value Theorem and takes each value only finitely many times is continuous. 
I've seen from a problem in Spivak's Calculus that this statement is true. 
Proof: For the case where $f$ takes on each value only once: If $f$ is not continuous, there exists $\epsilon gt 0$ such that there are $x$'s arbitrarily close to $a$ with $f(x)\gt f(a)+\epsilon$, or $f(x)\lt f(a)-\epsilon$. Say the first, then there are $x$'s arbitrarily close to $a$ with $x\gt a$ or $x\lt a$, with $f(x)\gt f(a)+\epsilon$. Say the first. Then by IVT, there is $x'\in (a,x)$ with $f(x')\lt f(a)+\epsilon.$ Also by assumption, there is a $y\in (a,x')$ with $f(y)\gt f(a)+\epsilon$. So by IVT, we can find a $x_1\in (y,x'),$ and $x_2\in (x',x)$ with $f(x_1)=f(x_2)=f(a)+\epsilon$, which is a contradiction.
The proof for the case where $f$ takes on each value only finitely many times proceeds by inductive reasoning to the above proof. 
However, I just came across a problem that states that if $h:[0,1]\to R$ takes each value exactly twice, then $h$ cannot be continuous on $[0,1]$. The proof to this problem contradicts the above statement.
Proof: Suppose that $h$ is continuous.
(1) By the Min-Max Theorem, $\exists c_1\in [0,1]$, which attains the maximum value of the function. Since each value is taken exactly twice, there is another $c_2\in [0,1]$, say $c_1\lt c_2$ such that $h(c_1)=h(c_2)$. 
Now if $0\lt c_1$, then we can choose $a_1,a_2\in (0,1)$ and a real number $k$ such that $0\lt a_1\lt c_1\lt a_2\lt c_2$ and $h(a_1)\lt k \lt h(c_1), h(a_2)\lt k \lt h(c_2)$. Then since $h(c_1)=h(c_2)$ are maximum and $h$ is continuous, by IVT there are $b_i\in (0,1)$ such that $h(b_i)=k$ and $a_1\lt b_1\lt c_1\lt b_2\lt a_2\lt b_3\lt c_2$. This is a contradiction. Hence $c_1=0.$
Likewise $c_2=1$.
(2) Now by the same reasoning as above, we can show that there are $d_1, d_2$ for which $h$ attains the minimum and $d_1=0, d_2=1$. 
Hence by (1) and (2) h is a constant function, which is a contradiction to the assumption.
Now I don't see any errors in the reasoning of either proof, but the conclusions seem contradictory. How can I reconcile this situation? 
 A: Here's a proof of the result that avoids induction. I'll assume $f$ is defined on some open interval and $f$ is bounded.
Suppose $f$ is discontinuous at $a.$ Then the IVP shows $f$ does not have a jump discontinuity at $a.$ Thus one of $\lim_{x\to a^-}f(x), \lim_{x\to a^+}f(x)$ fails to exist. Suppose WLOG $\lim_{x\to a^+}f(x)$ fails to exist. Then
$$m = \liminf_{x\to a^+}f(x) < M = \limsup_{x\to a^+}f(x).$$
From this it follows there are sequences $b_1 > a_1 > b_2 > a_2 > \cdots \to a$ such that $f(a_n) \to m, f(b_n) \to M.$ Choose $\epsilon>0$ such that $m+\epsilon <M-\epsilon.$ For large $n$ we will have $f(a_n) < m+\epsilon, f(b_n) > M - \epsilon.$ On the corresponding intervals $(a_n,b_n),f$ takes on all values in $[m+\epsilon,M-\epsilon]$ by the IVP. But the $(a_n,b_n)$ are disjoint, hence $f$ takes on each value in $[m+\epsilon,M-\epsilon]$ infinitely many times. This is a contradiction, giving the desired result. 
If $f$ is not bounded, then the above will apply to $\arctan f$ and give the result for $f.$ 
