Can a continuous function $f: \mathbb{R} \rightarrow \mathbb{R}$ with the following property exist: if $x \in \mathbb{Q}$, then $f(x) \in \mathbb{R} \setminus \mathbb{Q}$, and if $x \in \mathbb{R} \setminus \mathbb{Q}$, then $f(x) \in \mathbb{Q}$?
My attempt: I don't see any problem with this function. I wanted to check if it is consistent with the intermediate value theorem. Let $x_1, x_2 \in \mathbb{Q}$ and suppose that $x_1 < x_2$. Then $f(x_1) = y_1 \in \mathbb{R} \setminus \mathbb{Q}$ and $f(x_2) = y_2 \in \mathbb{R} \setminus \mathbb{Q}$. Intermediate value theorem says that for every $y$ satisfying $y_1 < y < y_2$ there exists an $x$ satisfying $x_1 < x < x_2$ such that $f(x) = y$. So I took a $y \in \mathbb{Q}$ satisfying $y_1 < y < y_2$ (I can do this since $\mathbb{Q}$ is dense in $\mathbb{R}$). Then, since $\mathbb{R} \setminus \mathbb{Q}$ is also dense in $\mathbb{R}$, there certainly exists an $x$ with the property that $x_1 < x < x_2$ and $f(x) = y$.
Or is there maybe something else wrong with this function that I don't see?