Give an example of a function $h$ that is discontinuous at every point of $[0,1]$, but with $|h|$ continuous on $[0,1]$

I would start with a function which I know is discontinuous at every point in $[0, 1]$. The standard one is

$$f(x) = \begin{cases} 1 & x \in \mathbb{Q}\cap[0, 1]\\ 0 & x \notin \mathbb{Q}\cap[0, 1] \end{cases}$$

which is the indicator function of the set $\mathbb{Q}\cap[0, 1]$. See if you can somehow adjust it for your purpose.


You can reverse engineer an example. You want $|f|$ to be continuous, so what is the simplest example of a continuous function? Of course it the constantly $0$ function. So, let's assume $|f(x)|=0$. But then, what can $f(x)$ possibly be? It has to be that $f(x)=0$ as well, which is a continuous function. So this does not work. Ok, then taking $|f(x)|=0$ was too hopeful. Let's try another example of a very simple continuous function, let's assume $|f(x)|=1$ for all $x\in [0,1]$. Now, for any given $x\in [0,1]$, what can $f(x)$ be? Now there are two possibilities: $f(x)=\pm 1$. Good, we have some freedom to play with the values of $f$. Now, playing with just the two values $\pm 1$, how do we make sure $f$ will not be continuous at any point? Well, we need to alternate like crazy between these two values. So we want to say something like $f(x)=1$ if $x$ is of type I, and $f(x)=-1$ if $x$ is not of type I, and such that points of type I are dense and points of type not I are also dense. Of course the rationals $\mathbb Q\cap [0,1]$ are dense and the irrationals $[0,1]-\mathbb Q$ are dense, so that will do the trick.