Prove that the function below is discontinuous everywhere except at $x = 0$ $f(x)=\begin{cases}0, \; x \notin \mathbb{Q} \\   x , \; x \in \mathbb{Q} \end{cases} $
I tried doing this proof through the epsilon delta definition using density of the rationals.
This is as far as I got:
Let $a \in \mathbb{R} , a \neq 0$ suppose $a \in \mathbb{Q} $ Let $ \delta > 0$ by the densitiy of the irrationals there exists $x \notin \mathbb{Q}$ such that $|x - a| < \delta$ then $f(x) = 0$ therefore $|f(a) - f(x)| = |f(a)| = |a|$
I'm not sure what to do from this point  
 A: Let $a \in \mathbb{Q}$, $a \not = 0$ and select $\epsilon = \dfrac {|a|}{2}$. In order for the limit to exist, there must exist a $\delta$ such that $|f(x) - f(a)| < \dfrac {|a|}{2}$ whenever $x \in (a- \delta, a+\delta)  - \{a\}$.  Because of the density of irrationals, for any $\delta$ there exists an irrational $x_0$ such that $x_0 \in (a- \delta, a+\delta)  - \{a\}$. But this implies that $|f(x_0) - f(a)| < \dfrac {|a|}{2} \implies |0-a| < \dfrac{|a|}{2}$, which is false.

The graph of $f$ is the blue line and the red line (with gaps in the of course). We can see that for any $a$, if we can find $\epsilon$ small enough so that the blue line is outside of $(f(a)-\epsilon, f(a) + \epsilon)$, we could show that there's no $\delta$ which satisfies the required proprety. 
If $a=2$, we could pick any $\epsilon$ smaller than $2$, such as $1.5$. But we needed to find an $\epsilon$ that would work no matter what $a$ is, and $\dfrac a2$ does the work. But you need to keep in mind that $a$ could be negative; since $\epsilon>0$, we had to throw in the absolute value. 
A: Hint:
If $x$ is irrational then by density of rationals there is a sequence of rationals $(x_n)$ converging to $x$ such that
$$x = \lim_n x_n =\lim_n f(x_n) \neq f(x) = 0.$$
Now consider rational $x \neq 0$.
A: Let $x$ be a real number. Then by the density of rational numbers there exists a sequence $\{x_{n} \}$ of rational numbers converging to $x$. But if $f$ is continuous then we have $f(x_{n}) \to f(x)$. But then $f$ would be identically zero, which is a contradiction. 
A: For continuity at the origin, let $\epsilon>0$ be given. Then we claim that if $|x| < \epsilon$, then $|f(x) - f(0)| =|f(x)| < \epsilon$. Indeed, if $x$ is rational, then $|f(x)| = 0 < \epsilon$ and if $x$ is irrational, then $|f(x)| = |x| < \epsilon$.
If $a$ is irrational, then by density of the rationals, there is some sequence $r_n\to a$ with $r_n$ rational for every $n$. By our definition of $f$, $|f(a) - f(r_n)| \ge \eta$ for some $\eta>0$ and all $n$, so $f$ is not continuous at $a$.
If $a$ is rational, then by the density of the irrationals, there is a sequence $\alpha_n\to a$ with $\alpha_n$ irrational for every $n$. By our definition of $f$, $|f(a) - f(\alpha_n)| \ge \eta'>0$ for some $\eta'$ and all $n$, so $f$ is not continuous at $a$.
A: I'd like to add an answer which uses directly epsilon-delta definition.
Let $x \in \mathbb{R}$ and $x \neq 0$. We want to show that $f$ is not continuous at $x$. So we want to find an $\epsilon > 0$ such that for all $\delta > 0$ the following condition is not satisfied:
$$\forall x' \in \mathbb{R} \text{,} \ (|x-x'| < \delta \implies |f(x)-f(x')| < \epsilon)$$
So, if $x \in \mathbb{Q}$, you can choose $\epsilon = |x/2|$ because it doesn't matter how small you choose $\delta$, there will be always a irrational $x'$ in that interval and then $|f(x)-f(x')| = |x|$ which is always greater then $\epsilon$. Other case is similar.
And for continuity at $0$, you don't actually need the density of $\mathbb Q$, just choose $\delta$ as $\epsilon$.
A: To complement the other answers for anyone who is curious, here is a proof using nonstandard analysis. (Note: $x \approx y$ means $x - y$ is infinitesimal.)
First, for any $\epsilon \approx 0$, note that $f(\epsilon)$ is either $0$ or $\epsilon$ -- either way $f(\epsilon) \approx 0 = f(0)$ , which shows that $f$ is continuous at $0$.
Next let $a \ne 0$ be real. To show $f$ is not continuous at $a$ we need to show that there exists $a' \approx a$ such that $f(a') \not \approx f(a)$. Since between two reals there is always a rational and irrational value, between any two hyperreals there is a hyperrational and hyperirrational value. So take $a'$ to be hyper-rational if $a$ is irrational, and hyper-irrational if $a$ is rational. In the former case, $f(a') = a' \not \approx 0 = f(a)$. In the latter case, $f(a') = 0 \not \approx a = f(a)$.
