This happens to be one of my favorite examples... :)

I know two solutions. They are both "algebraic" which seems appropriate for me being an algebraic geometer. I believe there should be a solution using classical analysis tools such as ${\rm lim}\ {\rm sup}$ and things like that, but that is not my territory. (However, I would be interested in seeing such a solution).

Anyway, here are my solutions. The first one is somewhat "high tech" but the second one only uses elementary notions.

1) Consider the group $(\mathbb R, +)$ and its (normal) subgroup $(\mathbb Q, +)$. Let $g:\mathbb R\to \mathbb R/\mathbb Q$ be the natural map to the quotient. Observe that $\mathbb R/\mathbb Q$ has the same cardinality as $\mathbb R$ and let $h:\mathbb R/\mathbb Q\to \mathbb R$ a bijective function. (Obviously this is not a group homomorphism, I only needed that to define $\mathbb R/\mathbb Q$ easily). Now, $f=h\circ g$ has the property you are looking for: For an arbitrary $\alpha\in\mathbb R$ let $\beta\in g^{-1}(\alpha)$ be a real number representing the coset $g^{-1}(\alpha)$, i.e., $\beta+\mathbb Q=g^{-1}(\alpha)$. Since $\beta+\mathbb Q$ is everywhere dense, every interval will contain an element (in fact infinitely many) of it, so $\alpha$ is taken as a value of $f$.

2) Using a bijective function between $\mathbb R$ and the interval $(0,1)$ that takes intervals to intervals shows that it is enough to construct a function $f:(0,1)\to (0,1)$ with the required property. Let $x\in(0,1)$ and write it in base $3$, that is $x$ will be expressed as a number between $0$ and $1$ with only $0,1,2$ appearing in it, something like $0.0101212222001222....$. Now, here is the rule to define the function:

a) If $x$ contains infinitely many $2$'s, then let $f(x)=1/2$ (or any number you want between $0$ and $1$).

b) If $x$ contains finitely many $2$'s, then remove all the digits of $x$ between the decimal point and the last $2$ (including that last $2$) and let $f(x)$ be the number defined by the remaining digits considered as a number written in base $2$.

The reason this function works is because on any interval one may find a number whose base $3$ expression is finite, ends in a $2$ and appending any variation of digits to this number is still in the interval.