Can we construct a function $f:\mathbb{R} \rightarrow \mathbb{R}$ such that it has intermediate value property and discontinuous everywhere? 
Can we construct a function $f:\mathbb{R} \rightarrow \mathbb{R}$ such that it has intermediate value property and discontinuous everywhere?

I think it is probable because we can consider 
$$  y = 
\begin{cases}
\sin \left( \frac{1}{x} \right), & \text{if } x \neq 0, \\
0, & \text{if } x=0.
\end{cases}
$$
This function has intermediate value property but is discontinuous on $x=0$.
Inspired by this example, let $r_n$ denote the rational number,and define 
$$  y = 
\begin{cases}
\sum_{n=1}^{\infty} \frac{1}{2^n} \left| \sin \left( \frac{1}{x-r_n} \right) \right|, & \text{if } x \notin \mathbb{Q}, \\
0, & \mbox{if }x \in \mathbb{Q}.
\end{cases}
$$
It is easy to see this function is discontinuons if $x$ is not a rational number. But I can't verify its intermediate value property.


Please look at the problem $1.3.29$ in Problems in Mathematical Analysis Vol II, Continuity and Differentiation, by Kaczor and Nowak (page 18 and page 159).

They have provided solutions also. Anyhow since one can't view it in Google books, I am Texing out the solution here.

Question: Recall that every $x \in (0,1)$ can be represented by a binary fraction $0.a_{1}a_{2}a_{3}\cdots$, where $a_{i} \in \{0,1\}$ and $i=1,2, \cdots$. Let $f: (0,1) \to [0,1]$ be defined by $$ f(x) = \overline{\lim_{n \to \infty}} \ \frac{1}{n} \sum\limits_{i=1}^{n}a_{i}$$
Prove that $f$ is discontinuous at each $x \in (0,1)$ but nevertheless has the intermediate value property.

Solution. We show that if $I$ is a subinterval of $(0,1)$ with non-empty interior then, $f(I)=[0,1]$. To this end, note that such an $I$ contains a sub-interval $\bigl(\frac{k}{2^{n_0}}, \frac{k+1}{2^{n_0}}\bigr)$. So it is enough to show that, $$f\biggl(\biggl(\frac{k}{2^{n_0}},\frac{k+1}{2^{n_0}}\biggr)\biggr)= [0,1]$$
Now observe that if $x \in (0,1)$ then either $x-\frac{m}{2^{n_0}}$ with some $m$ and  $n_0$ or $x \in \bigl(\frac{j}{2^{n_0}},\frac{j+1}{2^{n_0}}\bigr)$ with some $j=0,1, \cdots, 2^{n_0}-1.$ If $x = \frac{m}{2^{n_0}}$, then $f(x)=1$, and the value of $f$, at the middle point of $\bigl(\frac{k}{2^{n_0}}, \frac{k+1}{2^{n_0}}\bigr)$ is also $1$. Next if $x \in \bigl(\frac{j}{2^{n_0}}, \frac{j+1}{2^{n_0}}\bigr)$ then there is $x' \in \bigl(\frac{k}{2^{n_0}}, \frac{k+1}{2^{n_0}}\bigr)$, such that $f(x)=f(x')$.  Indeed, all numbers in $\bigl(\frac{k}{2^{n_0}}, \frac{k+1}{2^{n_0}}\bigr)$ have the same first $n_0$ digits, and we can find $x'$ in this interval for which all the remaining digits are as in the binary expansion of $x$. Since $$\overline{\lim_{n\to\infty}} \ \frac{\sum\limits_{i=1}^{n} a_{i}}{n} = \overline{\lim_{n\to\infty}} \ \frac{\sum\limits_{i=n_{0}+1}^{n} a_{i}}{n}$$ we get $f(x)=f(x')$.
Consequently it is enough to show that $f((0,1))=[0,1]$, or in other words, for each $y \in [0,1]$ there is $x \in (0,1)$ such that $f(x)=y$. It follows from the above that $1$ is attained, for example at $x =\frac{1}{2}$. To show that $0$ is also attained, take $x = 0.a_{1}a_{2}\cdots,$ where $$ a_{i}=\biggl\{\begin{array}{cc} 1 & \text{if} \ i=2^{k}, \ k=1,2, \cdots, \\\ 0 & \text{otherwise.}\end{array}$$
Then $$f(x) = \lim_{k \to \infty} \frac{k}{2^{k}}=0$$
To obtain $y=\frac{p}{q}$, where $p$ and $q$ are Co-prime positive integers, take $$ x = \underbrace{.00\cdots 0}_{q-p} \: \underbrace{11\cdots 1}_{p} \: \underbrace{00\cdots 0}_{q-p} \cdots,$$ where blocks of $q-p$ zeros alternate with blocks of $p$ ones.  Then $f(x) = \lim_{k\to\infty} \frac{kp}{kq}=\frac{p}{q}$.  Now our task is to show that every irrational $y \in [0,1]$ is also attained. We know that there is a sequence of rationals $\frac{p_n}{q_n}$, where each pair of $p_n$ and $q_n$ are co-prime converging to an irrational $y$. Let $$x = \underbrace{.00 \cdots 0}_{q_{1}-p_{1}} \: \underbrace{11\cdots 1}_{p_{1}} \: \underbrace{00 \cdots 0}_{q_{2}-p_{2}} \cdots,$$
Then $f(x) = \lim_{n \to \infty} \frac{p_{1} + p_{2} + \cdots + p_{n}}{q_{1} + q_{2} + \cdots + q_{n}} = \lim_{n \to \infty} \frac{p_{n}}{q_{n}} = y$.
Since $\displaystyle\lim_{n \to \infty} q_{n} = +\infty$, the second equality follows from the Stolz theorem.
