# Existence of a function satisfying given conditions

I was going through the topic of $Function$, its boundedness, continuity etc. I got a problem.

Does there exist a function defined on the closed interval $[a,b]$ which is....

1. bounded;

2. takes its maximum and minimum values;

3. takes all its values between the maximum and minimum values;

Then can we conclude that then this function is continuous at some points or subintervals on $[a,b]$.

Function below satisfies all three conditions above but it is discontinuous at every point on $[-1,1]$
$f(x)=\begin{cases} 1,&\text{if$x = 0$}\\ x,&\text{if x is rational,$x \neq 0$,$x\neq 1$}\\ -x,&\text{if x is rational,$x \neq 0$,$x\neq 1$,$x\neq -1$} \\ 0,&\text{if x = 1} \end{cases}$
It is impossible to draw the graph of the function $y = f(x)$ but the sketch below gives an idea of its behavior.
No. Take $f:[0,1]\to[0,1]$ such that $f(x) = x$ if $x$ is rational and $f(x)=1-x$ if $x$ is irrational. Well, okay, that's continuous at $x=\frac{1}{2}$, so just set $f(0) = \frac{1}{2}$ and $f(1/2) = 0$ and use the rule I gave above for all other values of $x$. :)